关于Discord bot的帮助命令的类别

时间:2018-04-24 16:32:11

标签: python discord

https://i.stack.imgur.com/Ezv5m.png

如您所见,该类别显示“无类别”。

我想要的帮助信息包括:

Serverinfo-informatiile despre server

online-Vezi daca botul este online

Jocuri (games):

ping: Pong pong pong! :D 

我的代码:

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

3 个答案:

答案 0 :(得分:0)

帮助消息类别由cogs分隔。

您可以使用bot.add_cog(cog)添加齿轮。

class Jocuri:
    """Jocuri documentations"""

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

bot.add_cog(Jocuri())

答案 1 :(得分:0)

当前对于任何其他来到这里的人,用于创建嵌齿轮的语法已更改。现在您的类必须继承自命令.Cog和pass_context已弃用。因此,如果您希望在bot的同一文件中包含一个嵌齿轮,则:

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')

我建议不要这样做,并且每个齿轮都有单独的文件,如果您想要一个示例,请查看:

答案 2 :(得分:0)

如果您不希望为简单的机器人添加齿轮,那么可以通过修改HelpCommand来重写“ No Category”字符串:https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.ext.commands.DefaultHelpCommand.no_category

例如:

...
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
...