You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python Discord Bot无法响应任何命令问题求助

Discord Bot前缀命令无响应排查方案
  • 检查消息内容Intent权限:Discord当前要求必须开启message_content Intent才能读取消息内容,进而触发前缀命令。你当前使用的discord.Intents.default()不包含该权限,需修改代码并在开发者平台开启对应权限:

    # 初始化Intents并开启消息内容权限
    intents = discord.Intents.default()
    intents.message_content = True
    bot = commands.Bot(command_prefix='!', help_command=None, case_insensitive=True, intents=intents)
    

    登录Discord开发者平台,进入你的Bot页面,找到「Privileged Gateway Intents」,开启Message Content Intent。

  • 修复代码语法错误:你的random_command函数中,print("Command executed)缺少闭合双引号,这会导致命令逻辑异常。修正后的代码:

    @bot.command()
    async def random_command(ctx):
        print("Command executed")
    
  • 清除缓存与重启:关闭Bot进程并彻底重启,确保没有残留的旧运行实例。必要时可以重新邀请Bot到服务器(邀请链接需包含applications.commands权限)。

  • 确认前缀未被修改:在on_ready事件中打印前缀,验证是否与设置一致,避免其他代码逻辑动态修改了前缀:

    print(f"当前Bot前缀: {bot.command_prefix}")
    

内容的提问来源于stack exchange,提问作者Carlos

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 07:44:16