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

Discord Bot重置令牌后message.content无内容问题求助

Discord Bot message.content 为空问题解决办法

问题原因及修复步骤

1. 未开启消息内容Intent权限

Discord 新版API要求必须明确开启message_content意图才能读取消息内容,默认的Intents.default()不包含该权限:

  • 代码层面:在定义intents时添加intents.message_content = True
  • 开发者后台设置:登录Discord开发者平台,找到对应Bot,在「Privileged Gateway Intents」下开启「Message Content Intent」开关

2. 代码缩进错误

你写的print(message.author.mention + ' ' + message.content)不在on_message事件函数内部,既不会在收到消息时执行,还会触发未定义变量错误。需要将该语句缩进,放入on_message函数范围内。

修改后的完整代码

import discord

intents = discord.Intents.default()
# 开启消息内容读取权限
intents.message_content = True
client = discord.Client(intents=intents)

@client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))

@client.event
async def on_message(message):
    if message.author == client.user:
        return

    # 将打印语句移入事件函数内
    print(message.author.mention + ' ' + message.content)

    if message.content.startswith('$hello'):
        await message.channel.send('Hello!')

client.run('TOKEN HERE')

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.28 07:22:37