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

Discord Bot无法在控制台显示消息 技术求助

解决Discord Bot无法输出消息文本的问题
  • 补全代码并开启消息内容权限
    你的代码存在两处问题:一是未导入discord模块,直接使用discord.Intents会报错;二是Discord v14+版本必须手动开启消息内容意图才能读取消息文本。修复后的代码如下:

    import discord
    from discord.ext import commands
    import data_bot
    
    intents = discord.Intents.default()
    intents.message_content = True  # 开启读取消息内容的权限
    bot = commands.Bot(command_prefix='!', intents=intents)
    
    @bot.event
    async def on_ready():
        print('Bot is ready!')
    
    @bot.event
    async def on_message(message):
        if message.author.bot:
            return  # 忽略其他机器人的消息
    
        print(f"{message.author}: {message.content}")
    
        await bot.process_commands(message)
    
    bot.run(data_bot.TOKEN)
    
  • 在Discord开发者平台配置权限
    登录Discord开发者平台,找到你的Bot应用,进入「Bot」页面,在「Privileged Gateway Intents」区域开启「Message Content Intent」开关。

完成以上两步后,重启Bot就能在控制台正常输出服务器内的用户消息了。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.01 05:39:52