You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

discord.py提示command is already existing alias错误但命令不存在如何解决

报错原因

这个报错是你代码里两处逻辑错误共同导致的:

  • 重复注册命令:@bot.command()装饰器本身已经自动将被装饰的函数注册为机器人命令,你后续又手动调用bot.add_command(hellothisisacommand),相当于对同一个命令执行了两次注册操作,哪怕反复修改命令名称,只要同时保留装饰器和add_command调用,就会触发重复注册错误。
  • 实例逻辑冲突:commands.Bot是discord.Client的子类,本身完全覆盖了Client的所有功能,你同时实例化了client = discord.Client()和bot = commands.Bot()两个独立的机器人实例,最后运行的还是client.run('token'),就算解决了命令注册问题,你写的bot命令也完全不会生效。
修正后的参考代码
import discord
from discord.ext import commands

intents = discord.Intents.default()
intents.members = True
intents.presences = True
# 必须开启消息内容权限才能触发前缀命令
intents.message_content = True
# 仅保留Bot实例即可,不需要额外创建Client
bot = commands.Bot(command_prefix = '/', intents=intents)

@bot.event
async def on_ready():
    print(f'We have logged in as {bot.user}')

@bot.command()
async def hellothisisacommand(ctx):
    # print是同步函数,不需要加await调用
    print(True)
    # 如果需要给频道返回消息可以使用下方代码
    # await ctx.send("命令触发成功")

# 移除多余的add_command调用
bot.run('你的机器人token')
额外注意事项
  • 你需要先在Discord开发者后台的机器人设置页,手动开启Message Content Intent权限,否则前缀命令无法被正常触发。
  • 同步方法不要加await调用,否则会抛出异常。

内容的提问来源于stack exchange,提问作者Henry

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.06 15:45:03