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



这里是我的机器人程序的完整代码,只是为了向您表明,除了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)

问题是这些行,它说帮助已经定义好了,但不是吗?当我使用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.

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

bot.remove_command('help')

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

Help是一个保留关键字,请尝试将函数命名为Help_1((:(或更有意义的名称(https://en.wikipedia.org/wiki/Reserved_word#:~:text=在%20a%20计算机%2C语言%20a中,单词%20may%20没有%20meaning。

最新更新