在discord.py中加载命令时出错



所以我正在构建一个机器人。这是代码:

import discord
from discord.ext import commands
from discord.utils import get
client = discord.Client()
bot = commands.Bot(command_prefix="&")
token = "<token censored for privacy>"
@client.event
async def on_ready():
print(f"{client.user} has connected to Discord.")
@bot.command()
async def repeat(ctx, args):
await ctx.send(args*10)
await ctx.send("You got rolled. Do it again.")
bot.add_command(repeat)
client.run(token)

但当我运行代码时,我会返回一个错误:discord.ext.commands.errors.CommandRegistrationError: The command repeat is already an existing command or alias.

我以前没有调用过bot.add_command函数。有人能帮忙吗
错误屏幕截图:discord.ext.commands.errors.CommandRegistrationError图像
代码屏幕截图:bot.py文件

当您想向bot添加命令时,有两个选项。

  • 您可以添加@bot.command()装饰器,或者
  • 您可以使用@commands.command()装饰器并运行bot.add_command(repeat)

这两者都会将您的命令添加到机器人程序中。有关添加命令的更多详细信息,请参阅命令的discord.py文档。

您看到错误的原因是您实际上添加了两次命令。

最新更新