【问题标题】:discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute 'qualified_name'discord.ext.commands.errors.CommandInvokeError:命令引发异常:AttributeError:'NoneType'对象没有属性'qualified_name'
【发布时间】:2022-01-25 05:06:44
【问题描述】:

我正在为我的机器人制作自定义帮助命令,这是我的代码。

class customhelpcommand(commands.HelpCommand):

    def __init__(self):
        super().__init__()
    
    async def send_bot_help(self, mapping):
        for cog in mapping:
            await self.get_destination().send(f"{cog.qualified_name}: {[command.name for command in mapping(cog)]}")
     

    async def send_cog_help(self, cog):
        await self.get_destination().send(f"{cog.qualified_name}: {[command.name for command in cog.get_commands()]}")

【问题讨论】:

  • 它给出了错误:AttributeError: 'NoneType' object has no attribute 'qualified_name'
  • 您首先检查对象(例如,如果 cog 不是 None: ...)那么您应该进一步移动。

标签: python discord.py command bots nonetype


【解决方案1】:

mapping 中的一些齿轮可能是 None。因此,您可以简单地检查它:

async def send_bot_help(self, mapping):
    for cog in mapping:
        if cog is not None:
            await self.get_destination().send(f"{cog.qualified_name}: {[command.name for command in mapping(cog)]}")

【讨论】:

  • 好的,会的,谢谢
猜你喜欢
  • 1970-01-01
  • 2021-02-05
  • 2021-01-30
  • 2021-12-07
  • 1970-01-01
  • 2022-01-05
  • 1970-01-01
  • 1970-01-01
  • 2021-12-04
相关资源
最近更新 更多