名称错误:"不和谐"未定义?



这是针对我正在制作的不和谐机器人,我试图设置机器人的状态。我找到了一个看起来像await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name="for e/info"))的答案,我把它放在一个on_ready事件函数中。但是,它给了我以下例外:

Ignoring exception in on_ready
Traceback (most recent call last):
File "C:UsersuserAppDataLocalProgramsPythonPython38-32libsite-packagesdiscordclient.py", 
line 312, in _run_event
await coro(*args, **kwargs)
File "C:UsersuserOneDriveDesktopEffeKtivebot.py", line 14, in on_ready
await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name="for 
e/info"))
NameError: name 'discord' is not defined

我觉得我错过了一个import.

您需要import discord代码的顶部。

您可能已经在单独的位置安装了 discord.py,请尝试将其安装到 C:\Windows\system32>。您也可能错过import。 如果要尝试添加命令,还必须:from discord.ext import commands。 您可以发布代码吗?

最新更新