当前位置: 首页 > 知识库问答 >
问题:

为什么我总是得到一个错误,说命令已经存在,而它显然不存在?

况浩邈
2023-03-14

这是我的机器人的完整代码,只是想告诉你,除了help命令之外,我没有在任何地方使用过help。这太令人困惑了,哈哈。

import asyncio
from discord.ext import commands

#todo
#Eco bot
#Leveling bot
#Help



#bot
token = 'token'
bot = commands.Bot(command_prefix='w')
#getting ID's

# list of banned words
filtered_words = ['bad words']

#help command
@bot.command(aliases=['help'])
async def help(ctx):
    author = ctx.message.author

    embed = discord.Embed(
        colour = Discord.Colour.blue
    )

    embed.set_author(name='help')
    embed.add_feild(name='clear', value='Alises: c, clean. Deleted a specified number of messages in the chat history.', inline=False)

@bot.event
async def on_ready():
    print("Hello I am online and ready!")
    #Bot status
    await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name=f"{len(bot.guilds)} server(s)"))

# Group message clearing (purge)
@bot.command(aliases=['c', 'clear'])
@commands.has_permissions(manage_messages = True)
async def clean(ctx, amount: int):
    amount += 1
    await ctx.channel.purge(limit = amount)
    amount -= 1
    msg = f"You've deleted {amount} messages"
    await ctx.send(msg, delete_after=10)

# auto mod
@bot.event
async def on_message(msg):
    for word in filtered_words:
        if word in msg.content:
            await msg.delete()
    await bot.process_commands(msg)

@bot.event
async def on_message_delete(msg):
    if msg.author.id != 835676293625282601:
        channel = bot.get_channel(398176354392342529)
        del_msg = await channel.send(":eyes:")
        await del_msg.send(del_msg)
        await asynciaito.sleep(10)
        await del_msg.delete()

bot.run(token)

问题是这些行,它说帮助已经定义,但它不是?当我使用清除命令而不是清除命令时,我也遇到了同样的问题。它只是不停地说这个命令已经被使用了。这让我很困惑,哈哈。

@bot.command(aliases=['help'])
async def help(ctx):
    author = ctx.message.author

    embed = discord.Embed(
        colour = Discord.Colour.blue
    )

    embed.set_author(name='help')
    embed.add_feild(name='clear', value='Alises: c, clean. Deleted a specified number of messages in the chat history.', inline=False)

以下是错误代码:

discord.ext.commands.errors.CommandRegistrationError: The command help is already an existing command or alias.

共有2个答案

长孙景天
2023-03-14

help是一个保留的关键字,尝试将你的函数命名为help_1():(或更有意义的)https://en.wikipedia.org/wiki/Reserved_word#:~: text=在计算机语言中,a, word可能没有意义。

戴鸿羲
2023-03-14

因为help已经是一个命令,所以您需要删除它。您可以在您的on_ready事件之前执行此操作。

bot.remove_command('help')

如果你感到困惑,这里有一个你可以参考的问题

 类似资料: