【问题标题】:discord.py "command is already existing alias" error, but it isntdiscord.py“命令已经存在别名”错误,但它不是
【发布时间】:2021-08-29 01:05:47
【问题描述】:

我最近决定学习如何使用 discord.py 命令,但我在添加命令时遇到了一些麻烦。无论我将命令更改为什么,当我尝试添加它时它总是会给出相同的错误:

discord.ext.commands.errors.CommandRegistrationError: The command hellothisisacommand is already an existing command or alias.

问题是,显然不是,而且无论我将命令更改为什么,它总是会出现此错误。这可能是什么原因造成的?代码如下。

import discord
from discord.ext import commands
import os

intents = discord.Intents.default()
intents.members = True
intents.presences = True
client = discord.Client()
bot = commands.Bot(command_prefix = '/')


@client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))

@bot.command()
async def hellothisisacommand(ctx):
    await print(True)
    
bot.add_command(hellothisisacommand)
client.run('token')

【问题讨论】:

    标签: python discord.py


    【解决方案1】:

    使用bot.command() 装饰器本质上等同于(并且排除了使用)bot.add_command

    您可以使用commands.command() 装饰器,然后调用bot.add_command,也可以使用bot.command() 装饰器,但不能同时使用。

    Read the docs for more info

    这是文档中的示例:

    有两种注册命令的方法。第一个是使用 Bot.command() 装饰器,如上例所示。第二种是在实例上使用 command() 装饰器,后跟 Bot.add_command()。

    本质上,这两者是等价的:

    from discord.ext import commands
    
    bot = commands.Bot(command_prefix='$')
    
    @bot.command()
    async def test(ctx):
        pass
    
    # or:
    
    @commands.command()
    async def test(ctx):
        pass
    
    bot.add_command(test)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-05
      • 1970-01-01
      • 2021-03-23
      • 2021-01-24
      • 2021-05-21
      • 2020-07-16
      相关资源
      最近更新 更多