NextCord.py开发Discord机器人$ping命令无响应无报错问题
Nextcord 机器人不响应前缀指令修复方案
问题表现
- 代码运行无报错,控制台正常输出Bot就绪提示
- 服务器内发送
$ping指令无任何回应,测试ctx.send方法仍无效 - 自认为Intents配置正确,但实际未完成必填配置
- 原问题代码如下:
import nextcord from nextcord.ext import commands from termcolor import colored import os os.system('color') logo = """ █┼┼ ███ ███- ███ ███ ███ ██▄ █┼┼ █▄┼ █┼█- █┼┼ █┼█ █▄┼ █┼█ █▄█ █▄▄ █▄█- ███ █▄█ █┼█ ███ """ print(colored(logo, "green")) print(colored("Lam Bot coded by LeoDev only!", "green")) TOKEN = 'token' bot = commands.Bot(command_prefix='$') @bot.event async def on_ready(): print(colored("Bot Ready!","green")) @bot.command() async def ping(ctx): await ctx.send('Pong!') bot.run(TOKEN)
核心问题
代码中未配置Intents参数,也未在Discord开发者后台开启消息内容特权意图。Nextcord 2.0及以上版本默认关闭消息内容读取权限,不完成配置的话机器人无法接收普通用户发送的消息内容,自然无法匹配指令触发逻辑。
修复步骤
- 开启开发者后台特权意图
- 进入Discord开发者平台对应机器人的管理页
- 找到Bot设置栏,下滑到Privileged Gateway Intents分区
- 打开Message Content Intent开关,保存设置
- 修改代码中Bot初始化逻辑,正确传入Intents参数
将原代码中bot = commands.Bot(command_prefix='$')替换为以下代码:intents = nextcord.Intents.default() intents.message_content = True bot = commands.Bot(command_prefix='$', intents=intents) - 重启机器人即可正常响应
$ping指令
补充排查项(改完仍失效时检查)
- 确认机器人在对应频道拥有「查看频道」「发送消息」「读取消息历史」权限
- 确认输入指令时使用半角
$符号,不要误输入全角$ - 确认机器人在服务器成员列表中显示为在线状态,而非离线
内容的提问来源于stack exchange,提问作者Leo4Real
相关产品推荐
相关产品推荐

