首页 > 解决方案 > 为什么我一直收到错误消息说命令已经存在,而它显然不存在?

问题描述

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

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)

问题是这些行,它说帮助已经定义,但不是吗?当我使用 clear 而不是 clean 时,我对 clean 命令也有同样的问题。它只是一直说该命令已被使用。这让我很困惑,哈哈。

@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.

标签: pythondiscorddiscord.pybots

解决方案


帮助是保留关键字,尝试将您的函数命名为 help_1(): (或更有意义的名称)https://en.wikipedia.org/wiki/Reserved_word#:~:text=In%20a%20computer%20language%2C %20a,word%20may%20have%20no%20意思


推荐阅读