情况:
我正在尝试使用 pycord 制作一个简单的 discord 机器人,但每次运行代码时都会出现此错误:
Traceback (most recent call last):
File "main.py", line 3, in <module>
bot = discord.Bot()
AttributeError: module 'discord' has no attribute 'Bot'
代码:
import discord
bot = discord.Bot()
@bot.slash_command()
async def test(ctx):
await ctx.send('Success!')
bot.run('token')
我做了什么:
我已经检查过我是否安装了 pycord 以及我的 token 是否正确。
最佳答案
PyCord 2 beta 1 刚刚发布,因此您现在可以安装它
pip install py-cord==2.0.0b1
而不是从源安装版本。
为了让示例正常工作,您需要将 applications.commands
范围添加到您的 OAuth2 URL 并在您的测试服务器上重新注册您的机器人。
另外,quickstart guide现在建议在创建 slash_command
时添加公会(服务器)ID 列表:
The
guild_ids
attribute contains a list of guilds where this command will be active. If you omit it, the command will be globally available, and may take up to an hour to register.
关于python - 如何修复错误 : module 'discord' has no attribute 'Bot' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69719970/