【问题标题】:When i do this cog command more than once then it gives an error discord.py当我多次执行此 cog 命令时,它会给出错误 discord.py
【发布时间】:2021-05-26 01:53:50
【问题描述】:

我做了一个帮助命令,当我执行一次命令时它就可以工作,但之后它停止工作,这意味着我必须重新运行整个代码。 (顺便说一句,这是一个齿轮)如果我多次执行命令,我得到的错误是Ignoring exception in command None: discord.ext.commands.errors.CommandNotFound: Command "help" is not found

import discord
from discord.ext import commands

class help(commands.Cog):

  def __init__(self, client):
    self.client = client



  @commands.command()
  async def help(self, ctx, cmd = "help"):
    self.client.remove_command("help")
    
    #help
    if cmd == "help":
      help_help_embed = discord.Embed(title = "Help Command", color = 0x00fd00)
      help_help_embed.add_field(name = "**:scroll: Info**", value = "`//help info`", inline = True)
      help_help_embed.add_field(name = "**:shield:Moderation**", value = "`//help moderation`", inline = True)
      help_help_embed.add_field(name = "**Channel**", value = "`//help channel`", inline = True)
      help_help_embed.add_field(name = "**:laughing: Fun**", value = "`//help fun`", inline = True)
      help_help_embed.add_field(name = "**:tools: Utility**", value = "`//help utility`", inline = True)
      help_help_embed.set_author(name = ctx.author, icon_url = ctx.author.avatar_url)

      await ctx.send(embed = help_help_embed)

    #info
    if cmd == "info":
      info_help_embed = discord.Embed(title = "**:scroll: Info Commands**", description = "//help {command}", color = 0x00fd00)
      info_help_embed.add_field(name = "Commands:", value = "`help`, `changelog`, `announcements`, `ping`, `credits`", inline = False)
      info_help_embed.set_author(name = ctx.author, icon_url = ctx.author.avatar_url)

      await ctx.send(embed = info_help_embed)

def setup(client):
  client.add_cog(help(client))

【问题讨论】:

    标签: python python-3.x discord.py


    【解决方案1】:

    嗯...也许删除

    self.client.remove_command("help")
    

    行?听起来它可能正在删除命令。

    编辑:基于 cmets,听起来它应该属于 __init__

    【讨论】:

    • 这会删除“标准”帮助命令,以便您可以制作自己的帮助命令。
    • 但它在help 处理程序中,这意味着当help 被调用时,它会自行删除。
    • 您的编辑完美地说明了它,应该在__init__函数中。
    • 我知道我不想说谢谢,因为我没有建议改进但不说谢谢感觉不对...谢谢:)
    猜你喜欢
    • 2019-04-10
    • 2021-06-29
    • 1970-01-01
    • 2021-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-23
    相关资源
    最近更新 更多