Categories On Help Command For Discord Bot
As you can see, the category says 'No category'. How can I change the category for a command? My code: @bot.command(pass_context=True) async def ping(ctx): '''Pong''' awai
Solution 1:
If you don't want the complexity of adding Cogs for a simple bot, you can rewrite the "No Category" string by modifying the HelpCommand: https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.ext.commands.DefaultHelpCommand.no_category
For example:
...
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
)
The result should look like:
This is the bot description
Commands:
something Do something
...
Solution 2:
Help message categories are separated by cogs.
You can add cogs by using bot.add_cog(cog)
.
class SomeCategory:
"""Category documentations"""
@commands.command(pass_context=True)
async def ping(self, ctx):
"""Pong"""
await bot.say(":ping_pong: Pong!")
print ("user has pinged")
bot.add_cog(SomeCategory())
Solution 3:
Currently for any other people that come here, the syntax for creating cogs has been changed. Now your class has to inherit from commands.Cog and pass_context has been depreciated. So if you want to have a cog in the same file of the 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')
I recommend not doing this and having separate files for each cog, if you want a example on that, check out:
Post a Comment for "Categories On Help Command For Discord Bot"