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

Discord.py无报错但机器人无响应问题求助

解决Discord.py机器人不响应$hello指令的问题

1. 正确配置Intents(核心问题)

Discord.py 2.0及以上版本必须显式启用消息内容意图,否则机器人无法读取消息内容来识别指令:

  • 先去Discord开发者门户,找到你的机器人应用,进入「Privileged Gateway Intents」,开启Message Content Intent
  • 代码中初始化机器人时指定完整Intents:
    import discord
    from discord.ext import commands
    
    # 初始化意图,启用消息内容权限
    intents = discord.Intents.default()
    intents.message_content = True
    
    bot = commands.Bot(command_prefix='$', intents=intents)
    
    @bot.command()
    async def hello(ctx):
        await ctx.send('Hello!')
    
    bot.run('你的机器人令牌')
    

2. 处理「Shard ID None」提示

这个提示对小型机器人功能无影响,只是未启用分片的默认提示。如果要消除它,初始化Bot时指定分片数即可:

bot = commands.Bot(command_prefix='$', intents=intents, shard_count=1)

3. 额外排查项

  • 确认机器人在目标服务器拥有读取消息和发送消息的权限
  • 检查发送的指令是否严格匹配前缀+指令名(即$hello,无多余空格)
  • 确认代码中@bot.command()装饰器未写错,函数名与指令名称完全一致

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.21 22:42:01