Python Discord bot帮助命令中的类别

Python Discord bot帮助命令中的类别,python,discord,Python,Discord,如您所见,类别显示“无类别”。 如何更改命令的类别 我的代码: @bot.command(pass_context=True) async def ping(ctx): """Pong""" await bot.say(":ping_pong: Pong!") print ("user has pinged") 帮助消息类别由COG分隔 可以使用添加齿轮 目前,对于来到这里的任何其他人,创建COG的语法已经更改。现在,您的类必须从命令继承。Cog和pass_上下文已贬值

如您所见,类别显示“无类别”。 如何更改命令的类别

我的代码:

@bot.command(pass_context=True)
async def ping(ctx):
    """Pong"""
    await bot.say(":ping_pong: Pong!")
    print ("user has pinged")

帮助消息类别由COG分隔

可以使用添加齿轮


目前,对于来到这里的任何其他人,创建COG的语法已经更改。现在,您的类必须从命令继承。Cog和pass_上下文已贬值。因此,如果您希望在机器人的同一文件中有一个cog:

import discord
from discord.ext import commands

class MyCog(commands.Cog):
   """Cog description"""

    @commands.command()
    async def ping(self, ctx):
        """Command description"""
        await ctx.send("Pong!")

bot = commands.Bot(command_prefix="!")
bot.add_cog(MyCog())
bot.run('token')
我建议不要这样做,每个cog都有单独的文件,如果您想要一个例子,请查看:


如果您不想为一个简单的机器人添加齿轮的复杂性,您可以通过修改HelpCommand来重写“无类别”字符串:

例如:

...
from discord.ext import commands
...

# Change only the no_category default string
help_command = commands.DefaultHelpCommand(
    no_category = 'Commands'
)

# Create the bot and pass it the modified help_command
bot = commands.Bot(
    command_prefix = commands.when_mentioned_or('?'),
    description = description,
    help_command = help_command
)
结果应该如下所示:

This is the bot description

​Commands:
  something Do something
...

我实际上忘记了怎么做了(因为我有一个坏习惯,我更关心的是功能而不是组织),但是如果你访问Discord API服务器,或者Egg和Sebi的机器人教程服务器,他们肯定能帮到你。您正在查找的信息也可能在discord.py API中找到:请不要在将来重新发布问题,请编辑您现有的问题以明确说明。当一个问题被标记为不清楚时,它实际上被搁置。编辑不清楚的问题后,评论员可以投票重新打开你的帖子。你能给我Egg和Sebi的机器人教程服务器吗?类别由“cogs”分隔,使用add_cog函数创建cog类。在add_cog之后我需要键入什么我的类别名称或其他内容?
This is the bot description

​Commands:
  something Do something
...