NameError: name 'asyncio' is not defined; In running discord bot
NameError: name 'asyncio' is not defined; In running discord bot
我正在为我制作的服务器开发一个小型 discord 机器人,但是我 运行 遇到了问题。每当我尝试 运行 机器人(使用 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>
我尝试通过 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)
是不是我没有安装正确?我是否错误地调用了 asyncio?感谢任何帮助,如果需要我可以提供更多信息。
您忘记了 import asyncio
- 在使用之前添加导入,它应该可以工作。
您忘记在代码中导入 asyncio
。
只需将以下内容添加到代码的第一行
import asyncio
我正在为我制作的服务器开发一个小型 discord 机器人,但是我 运行 遇到了问题。每当我尝试 运行 机器人(使用 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>
我尝试通过 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)
是不是我没有安装正确?我是否错误地调用了 asyncio?感谢任何帮助,如果需要我可以提供更多信息。
您忘记了 import asyncio
- 在使用之前添加导入,它应该可以工作。
您忘记在代码中导入 asyncio
。
只需将以下内容添加到代码的第一行
import asyncio