You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在自定义Help命令中隐藏指定的Owner Cog?

解决Discord.py自定义Help命令隐藏Owner Cog的问题

只需在遍历Cog的循环中添加过滤逻辑,跳过名为"owner"的Cog即可。修改后的完整代码如下:

@commands.hybrid_command(
    name="help", description="Список всех доступных команд бота."
)
@checks.not_blacklisted()
async def help(self, context: Context) -> None:
    prefix = self.bot.config["prefix"]
    embed = discord.Embed(
        title="Помощь", description="Список доступных команд:", color=0x9C84EF
    )
    for i in self.bot.cogs:
        # 跳过owner cog,不显示在帮助菜单中
        if i.lower() == "owner":
            continue
        cog = self.bot.get_cog(i.lower())
        commands = cog.get_commands()  
        data = []
        for command in commands:
            description = command.description.partition("\n")[0]
            data.append(f"{prefix}{command.name} - {description}")
        help_text = "\n".join(data)
        embed.add_field(
            name=i.capitalize(), value=f"```{help_text}```", inline=False
        )
    await context.send(embed=embed)

关键说明:

  • 在遍历self.bot.cogs的循环开头,通过i.lower() == "owner"判断当前Cog是否为目标隐藏项,用continue直接跳过该迭代,不再执行后续添加字段的逻辑。
  • 使用lower()是为了兼容Cog名称的大小写差异,确保无论注册时是"Owner"还是"owner"都能被正确过滤。

内容的提问来源于stack exchange,提问作者Qaveru

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.29 01:27:16