discord.py机器人在线但无响应无报错,请求技术帮助
问题解决:Discord机器人在线但无指令响应
核心原因:消息内容意图未开启
Discord.py v2.x版本后,message_content属于特权网关意图,默认不会被启用,导致机器人无法读取消息内容,自然无法触发指令逻辑。
解决步骤:
在Discord开发者平台开启权限
- 打开你的机器人应用页面,切换到「Bot」标签页
- 找到「Privileged Gateway Intents」区域,开启「Message Content Intent」
修改代码中的Intents配置
将原代码的Intents初始化部分替换为:import os 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 if message.content.startswith('$hello'): await message.channel.send('Hello!') client.run(os.environ['TOKEN'])
额外检查项
- 确认机器人在目标服务器中拥有「读取消息/查看频道」和「发送消息」的权限
- 确认指令输入完全正确(比如
$hello没有多余空格或符号)
内容的提问来源于stack exchange,提问作者Harsimran Singh
相关产品推荐
相关产品推荐

