制作Discord Bot报错commands.bot not callable该如何解决
问题原因
你代码第4行调用的commands.bot拼写错误,discord.py 库中discord.ext.commands模块下的机器人客户端类为大写开头的Bot,小写的bot是模块下的子模块对象,不可被调用,因此触发类型错误。
修复方案
将第4行的小写bot修改为大写Bot即可,如果你使用的是 v2.0 及以上版本的 discord.py,还需要额外声明机器人运行所需的网关意图(Intents),完整可运行代码示例如下:
import discord from discord.ext import commands # 声明网关意图,默认开启基础权限 intents = discord.Intents.default() # 如果需要读取消息内容触发前缀命令,需要额外开启以下配置,同时需要在Discord开发者后台的Bot页面开启Message Content Intent开关 # intents.message_content = True bot = commands.Bot(command_prefix=".", intents=intents) @bot.event async def on_ready(): print("bot is ready!") bot.run("你的Bot令牌此处替换")
内容的提问来源于stack exchange,提问作者StrixTyphoon
相关产品推荐
相关产品推荐

