python - 为什么我一直收到错误消息说命令已经存在,而它显然不存在?
问题描述
这是我的机器人的完整代码,只是为了告诉你我没有在任何地方使用过帮助,除了帮助命令。这太令人困惑了哈哈。
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_1(): (或更有意义的名称)https://en.wikipedia.org/wiki/Reserved_word#:~:text=In%20a%20computer%20language%2C %20a,word%20may%20have%20no%20意思。
推荐阅读
- python - 数据框类型错误:“方法”对象不可迭代
- android - 如何在 Android Studio 中更改 FirebaseReference 的 Firebase URL?
- java - 当我有映射时,出现没有映射的异常
- kubernetes - 将其公开为服务后无法访问由谷歌 kubernetes 引擎(GKE)创建的 IP
- javascript - Discord.JS 13 斜杠命令显示目标用户的特定用户角色并嵌入,
- node.js - Websockets 在我使用 nginx 托管在 EC2 上的节点服务器上的生产失败。关于如何从邮递员调试 1006 异常关闭错误的任何提示?
- typescript - 在nestjs中添加松弛/螺栓时超时
- oracle - 如何提高activejdbc启动性能?
- azure - ServiceBus 消息传递时间可靠吗?
- junit - Leiningen 不运行 JUnit 测试用例