discord.py "sub help command"

Question:

I was wondering if it’s possible to make a somewhat "sub help command" basically if I were to do ;help mute it would show how to use the mute command and so on for each command. Kinda like dyno how you can do ?help (command name) and it shows you the usage of the command. I have my own help command already finished but I was thinking about adding to it so if someone did ;help commandname it would show them the usage such as arguments I tried at the bottom but I don’t think that will work. If you know how please let me know

@client.hybrid_command(name = "help", with_app_command=True, description="Get a list of commands")
@commands.guild_only()
async def help(ctx, arg = None):
    pages = 3
    cur_page = 1
    roleplayembed = discord.Embed(color=embedcolor, title="Roleplay Commands")
    roleplayembed.add_field(name=f"{client.command_prefix}Cuddle", value="Cuddle a user and add a message(Optional)",inline=False)
    roleplayembed.add_field(name=f"{client.command_prefix}Hug", value="Hug a user and add a message(Optional)",inline=False)
    roleplayembed.add_field(name=f"{client.command_prefix}Kiss", value="Kiss a user and add a message(Optional)",inline=False)
    roleplayembed.add_field(name=f"{client.command_prefix}Slap", value="Slap a user and add a message(Optional)",inline=False)
    roleplayembed.add_field(name=f"{client.command_prefix}Pat", value="Pat a user and add a message(Optional)",inline=False)
    roleplayembed.set_footer(text=f"Page {cur_page+1} of {pages}")
    roleplayembed.timestamp = datetime.datetime.utcnow()
    basicembed = discord.Embed(color=embedcolor, title="Basic Commands")
    basicembed.add_field(name=f"{client.command_prefix}Waifu", value="Posts a random AI Generated Image of a waifu",inline=False)
    basicembed.add_field(name=f"{client.command_prefix}8ball", value="Works as an 8 ball",inline=False)
    basicembed.add_field(name=f"{client.command_prefix}Ara", value="Gives you a random ara ara from Kurumi Tokisaki",inline=False)
    basicembed.add_field(name=f"{client.command_prefix}Wikipedia", value="Search something up on the wiki",inline=False)
    basicembed.add_field(name=f"{client.command_prefix}Userinfo", value="Look up info about a user",inline=False)
    basicembed.add_field(name=f"{client.command_prefix}Ask", value="Ask the bot a question",inline=False)
    basicembed.add_field(name=f"{client.command_prefix}Askwhy", value="Ask the boy a question beginning with 'why'",inline=False)
    basicembed.add_field(name=f"{client.command_prefix}Avatar", value="Get a user's avatar or your own avatar",inline=False)
    basicembed.set_footer(text=f"Page {cur_page} of {pages}")
    basicembed.timestamp = datetime.datetime.utcnow()
    moderationembed = discord.Embed(color=embedcolor, title="Moderation Commands")
    moderationembed.add_field(name=f"{client.command_prefix}Kick", value="Kick a member",inline=False)
    moderationembed.add_field(name=f"{client.command_prefix}Ban", value="Ban a member",inline=False)
    moderationembed.add_field(name=f"{client.command_prefix}Slowmode", value="Set the slowmode of a channel",inline=False)
    moderationembed.add_field(name=f"{client.command_prefix}Purge", value="Purge an amount of messages in a channel",inline=False)
    moderationembed.add_field(name=f"{client.command_prefix}Mute", value="Mute a member for a time and reason",inline=False)
    moderationembed.add_field(name=f"{client.command_prefix}Unmute", value="Unmute a member for a time and reason",inline=False)
    moderationembed.set_footer(text=f"Page {cur_page+2} of {pages}")
    moderationembed.timestamp = datetime.datetime.utcnow()
    contents = [basicembed, roleplayembed, moderationembed]
    if arg == None:
        message = await ctx.send(embed=contents[cur_page-1])
        

        await message.add_reaction("◀️")
        await message.add_reaction("▶️")

        def check(reaction, user):
            return user == ctx.author and str(reaction.emoji) in ["◀️", "▶️"]
       
        while True:

            try:
                reaction, user = await client.wait_for("reaction_add", timeout=60, check=check)
                if str(reaction.emoji) == "▶️":
                    cur_page += 1
                elif str(reaction.emoji) == "◀️": 
                    cur_page -= 1
                if cur_page > pages: #check if forward on last page
                    cur_page = 1 
                elif cur_page < 1: #check if back on first page
                    cur_page = pages 
                await message.edit(embed=contents[cur_page-1])
                await message.remove_reaction(reaction, user)

            except asyncio.TimeoutError:
                await message.delete()
                break
    if arg.lower() == client.command_name:
        await ctx.reply(f"{client.command_prefix}{client.command_name}{client.command_argument}")
Asked By: TheRealKurumi

||

Answers:

Yes, it is possible to create a help command for a discord bot that provides information about specific commands. The way to do this will depend on how you have structured your code, but one approach would be to define a dictionary that maps each command to its usage instructions, and then use that dictionary to look up the instructions for a given command when the help command is called.

For example, you could define a dictionary like this:

commands = {
    "mute": "This command is used to mute a user in the server. Usage: ;mute @user",
    "ban": "This command is used to ban a user from the server. Usage: ;ban @user",
    ...
}

Then, when the help command is called, you could use this dictionary to look up the usage instructions for the specified command. Here is an example of how that could work:

@bot.command()
async def help(ctx, command: str):
    if command in commands:
        await ctx.send(commands[command])
    else:
        await ctx.send("I'm sorry, I don't have information about that command.")

Hope this helps!

Answered By: A-poc
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.