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
相关产品推荐
相关产品推荐

