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

Python-Discord机器人命令无响应:!hello指令失效问题排查

问题原因及解决方法

核心原因:缺少消息内容权限(Message Content Intent)

从discord.py v2.0版本开始,Discord要求机器人必须明确开启Message Content Intent才能读取用户发送的消息内容(包括命令前缀和命令文本)。你的代码仅使用discord.Intents.default(),这个默认权限集不包含消息内容权限,导致机器人根本接收不到!hello命令的内容,自然无法做出响应。

解决步骤

  1. 在Discord开发者后台开启权限

    • 进入Discord开发者门户的机器人应用页面
    • 切换到「Bot」标签页,找到「Privileged Gateway Intents」区域
    • 开启「Message Content Intent」开关
  2. 修改代码中的Intents设置
    在代码里明确添加消息内容权限:

    import discord
    from discord.ext import commands
    
    intents = discord.Intents.default()
    # 开启消息内容权限
    intents.message_content = True
    
    bot = commands.Bot(command_prefix='!', intents=intents)
    
    @bot.event
    async def on_ready():
        print(f'Login bot: {bot.user}')
    
    @bot.command()
    async def hello(ctx):
        await ctx.send('Hi, there!')
    
    bot.run('你的机器人令牌')
    

其他排查点

  • 确认机器人令牌token无拼写错误或过期
  • 确保机器人在服务器中拥有「发送消息」「读取消息历史」等必要权限
  • 检查是否有服务器自动删除命令消息,导致机器人未接收

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.19 15:30:43