python - 如何修复错误 : module 'discord' has no attribute 'Bot'

标签 python discord pycord

情况:

我正在尝试使用 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/

相关文章:

python - 如何在 Django Tastypie 中调用 Resource 实例?

python - 在 python 中使用非标准类型进行类型转换

python - Django Postman 实现发送消息

python - 回复后如何删除用户输入的命令

python - 不和谐用十六进制颜色创建角色(pycord)

python - 使用 on_application_command_error() 与 @command.error 进行回溯处理

python - Timer_fd python ?有没有等价物

javascript - 斜杠命令 "unknown interaction"

javascript - 获取/监听 channel 中的新消息

python - 使用后禁用按钮