我不明白它是如何工作的

问题描述 投票:0回答:1

我有一个包含命令“!forma”的代码,当我在discord中输入此命令时,通知我“[2024-02-10 23:37:21] [错误]discord.ext.commands.bot:忽略命令中的异常 无 Discord.ext.commands.errors.CommandNotFound:找不到命令“forma””

intents = discord.Intents.default().all()
intents.message_content = True
bot = commands.Bot(command_prefix="!", intents=intents)
class VerificationBot(commands.Bot):
  def __init__(self):
      super().__init__(command_prefix="!", intents=discord.Intents.default().all())

  @commands.command(name="forma")
  async def forma(self, ctx, nickname):
    """
    Обрабатывает команду "!forma" и отправляет запрос на верификацию.

    Args:
        ctx: контекст команды
        nickname: введенный никнейм
    """

    if not nickname:
      await ctx.send("**Ошибка!** Вы не указали никнейм. Пожалуйста, используйте команду `!forma` с вашим никнеймом.")
      return

我希望团队合作

discord.py
1个回答
0
投票

首先,您要导入

discord
commands
吗?

import discord
from discord.ext import commands

另外,从

all()
中删除
intents
。即:

intents = discord.Intents.default()

如果您使用

@commands.command()
装饰器,那么您需要调用
bot.add_command(forma)
但您将遇到的问题是所有内容都在类中。就我个人而言,我会在没有课程的情况下让它工作,然后添加它或您需要的任何其他内容。不过,
forma
这个函数只需将其放在类之外,然后
bot.add_command(forma)
就可以工作了。

Here 是指向

DiscordPy
命令文档的链接。

这应该是一个很好的工作起点,但我可能错过了一些东西。

import discord
from discord.ext import commands

intents = discord.Intents.default()
intents.message_content = True

bot = commands.Bot(command_prefix="!", intents=intents)

@commands.command()
async def forma(ctx, nickname):
    """
    Обрабатывает команду "!forma" и отправляет запрос на верификацию.

    Args:
        ctx: контекст команды
        nickname: введенный никнейм
    """

    if not nickname:
      await ctx.send("**Ошибка!** Вы не указали никнейм. Пожалуйста, используйте команду `!forma` с вашим никнеймом.")
      return
    
    # TODO: nickname is set so add additional code here

bot.add_command(forma)
© www.soinside.com 2019 - 2024. All rights reserved.