我开始使用discord.py在discord上制作一个机器人,但有一个我无法解决的问题。目的是创建一个使bot消息成为具有特定消息的特定通道的命令。这是代码
@commands.has_any_role("Phantom","XX")
async def msg(ctx,*, Msg = None):
await ctx.send(f"Please give the channel ID. You can do this by saying ``.ID (IDhere)``")
@client.command()
async def ID(ctx,*, ID = 0):
message = Msg
channel = client.get_channel(ID)
await channel.send(message)
await ctx.send(f":white_check_mark: Message sent")
我第一次运行整个命令时,一旦我说了.msg命令,我就收到了此错误:
File "C:\Users\Jack\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\bot.py", line 892, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\Jack\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 797, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\Jack\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 92, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: ClientException: Command ID is already registered.
答案 0 :(得分:0)
使用该命令之前,您必须先注册该命令,因此解决方案是在程序顶部定义该命令,以便在启动时仅加载您要使用的所有命令。
您正在寻找的是:How to fix "discord.errors.ClientException: Command kick is already registered." error?