Python开发Discord Bot的!test命令无输出问题求助
解决Discord Bot !test命令无响应问题
排查及修复步骤
- 补充Bot启动语句:你的代码末尾缺少启动Bot的核心执行语句,必须添加
bot.run('你的Bot令牌'),将你的Bot令牌替换为Discord开发者平台获取的真实令牌。 - 启用Message Content Intent:登录Discord开发者平台,进入你的Bot应用页面,在「Privileged Gateway Intents」板块开启Message Content Intent,否则Bot无法读取消息内容,无法触发命令响应。
- 检查命令输入格式:确保发送命令时严格使用
!test格式,前缀!与命令名之间无多余空格或特殊符号。 - 确认Bot服务器权限:保证Bot在目标服务器中拥有「发送消息」「读取消息」等基础权限,否则无法发送回复内容。
修复后的完整代码
import discord from discord.ext import commands intents = discord.Intents.default() intents.message_content = True bot = commands.Bot(command_prefix='!', intents=intents) @bot.event async def on_ready(): print('ready') game = discord.Game('r') await bot.change_presence(status=discord.Status.online, activity=game) @bot.command(name='test') async def t(ctx): await ctx.reply("1") # 替换为你的Bot令牌 bot.run('YOUR_BOT_TOKEN_HERE')
内容的提问来源于stack exchange,提问作者C P
相关产品推荐
相关产品推荐

