NameError:未定义名称"asyncio"; 在运行discord bot

Set*_* G. 2 python python-3.x python-asyncio discord.py

我正在为我制作的服务器开发一个小的discord bot,但是我遇到了一个问题.每当我尝试运行bot(使用python3.4 lilac.py)时,我都会收到以下错误:

Traceback (most recent call last):
  File "lilac.py", line 7, in <module>
    @asyncio.coroutine
NameError: name 'asyncio' is not defined
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0xb61ad470>
Run Code Online (Sandbox Code Playgroud)

我尝试通过安装它python3.4 -m pip install asyncio,即使它说安装成功,我仍然得到错误.这是完整的代码:

import discord
from discord.ext import commands

bot = commands.Bot(command_prefix='&&', description="Description     here")

@bot.event
@asyncio.coroutine
def on_ready():
    print('Logged in as')
    print(bot.user.name)
Run Code Online (Sandbox Code Playgroud)

有什么我没有正确安装?我是否错误地调用了asyncio?任何帮助表示赞赏,如果需要,我可以提供更多信息.

小智 14

您忘记导入asyncio代码了.只需将以下内容添加到代码的第一行即可

import asyncio
Run Code Online (Sandbox Code Playgroud)