Nextcord机器人CommandNotFound问题:!hello与/hello均无法触发
问题解决步骤
1. 前缀命令!hello无效的原因
你只定义了斜杠命令/hello,没有创建对应的前缀命令!hello,机器人自然找不到该命令。需要添加前缀版本的命令:
@client.command() async def hello(ctx): await ctx.send("Hello There")
2. 斜杠命令/hello无效的原因
代码里的testingServerID是字符串"server id",但guild_ids要求传入整数类型的服务器ID,字符串会导致斜杠命令无法正确注册到目标服务器。
把testingServerID替换成实际的服务器数字ID,比如:
testingServerID = 123456789012345678 # 换成你的服务器真实ID
修改后的完整代码
import nextcord from nextcord import Interaction from nextcord.ext import commands intents= nextcord.Intents.all() intents.message_content = True intents.members = True client = commands.Bot(command_prefix="!", intents=intents) @client.event async def on_ready(): print("Bot is Ready For Use!") # 替换为你的服务器整数ID testingServerID = 123456789012345678 # 斜杠命令 @client.slash_command(name='hello', description="Replies with Hello", guild_ids=[testingServerID]) async def hello_slash(interaction: Interaction): await interaction.response.send_message("Hello There") # 前缀命令 @client.command() async def hello(ctx): await ctx.send("Hello There") token = "my token token" client.run(token)
额外检查项
- 确认Discord开发者平台中,机器人的消息内容意图和服务器成员意图已开启(代码里设置了,但要确保平台端同步开启)。
- 确保机器人已邀请到目标服务器,且拥有发送消息的权限。
内容的提问来源于stack exchange,提问作者Professor Seemo
相关产品推荐
相关产品推荐

