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

Pycord中Bot类获取message.content无内容的问题求助

问题:Pycord Bot类无法获取message.content内容

使用Pycord的Bot类监听消息时,message.content始终为空,仅输出Received ,但用Client对象可以正常获取内容,却无法使用slash命令。已完成以下排查:

  • 尝试过@bot.event和@bot.listen装饰器(带/不带括号)
  • 机器人已配置必要权限
  • Discord开发者门户已开启message content意图

简化后的代码如下:

import discord

bot = discord.Bot()

token = [token would go here]
intents = discord.Intents.default()
intents.typing = True
intents.messages = True
intents.message_content = True

@bot.event
async def on_message(message):
    print(f'Received {message.content}')

bot.run(token)

解决方案

问题核心在于Intents的初始化顺序错误:你先创建了Bot实例,之后才配置Intents,导致Bot没有使用你开启了message_content权限的配置。

修正步骤:先完成Intents的配置,再将其传入Bot的构造函数中:

import discord

# 先初始化并配置Intents
intents = discord.Intents.default()
intents.typing = True
intents.messages = True
intents.message_content = True

# 将配置好的Intents传入Bot实例
bot = discord.Bot(intents=intents)

token = [token would go here]

@bot.event
async def on_message(message):
    print(f'Received {message.content}')

bot.run(token)

额外说明:

  • Pycord的Bot类继承自Client,只要正确配置Intents,就能同时支持消息监听和slash命令
  • 确认机器人在服务器中的权限包含读取消息历史(确保能获取消息内容)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.28 00:20:55