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

Discord Bot无法读取消息内容?开启Message Intent仍无效求助

Discord Bot 接收消息内容为空的排查与解决方法
  • 检查消息内容的获取属性是否正确
    不同Discord开发库获取消息文本的属性不一样,比如discord.py要用message.content,discord.js同样用message.content,如果拼写错误或者误用了废弃属性,就会拿到空值。直接核对代码里的属性名,确保是对应库的正确写法。

  • 确认Message Intent的完整配置
    光在Discord开发者门户开启Message Content Intent还不够,必须在代码里启用对应的意图:

    • 用discord.py的话,代码要这么写:
      intents = discord.Intents.default()
      intents.message_content = True
      client = discord.Client(intents=intents)
      
    • 用discord.js的话,需要包含MessageContent意图:
      const { Client, GatewayIntentBits } = require('discord.js');
      const client = new Client({ 
        intents: [
          GatewayIntentBits.Guilds, 
          GatewayIntentBits.GuildMessages, 
          GatewayIntentBits.MessageContent
        ] 
      });
      
  • 验证Bot的服务器权限
    确保Bot在目标服务器中有「查看频道」和「读取消息历史」的权限,没有这些权限的话,Bot可能只能检测到消息存在,但拿不到内容。可以在服务器设置的「角色」面板里给Bot分配对应的权限。

  • 排查消息类型问题
    如果发送的是嵌入消息、带附件的消息或者系统通知(比如成员加入提醒),这类消息的content字段本身就是空的。可以在代码里先判断消息类型,只处理普通文本消息:

    # discord.py 示例
    if message.type == discord.MessageType.default:
        print(f"got a message : '{message.content}' from @{message.author}")
    else:
        print(f"收到非文本消息 from @{message.author}")
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.22 05:15:58