简体   繁体   中英

How can I make a embed help slash command using pycord?

how can I make the embed help command that uses slash commands?

like this help command

i have only non slash command:

@bot.command()
async def help(ctx, args=None):
    help_embed = discord.Embed(title="My Bot's Help!")
    command_names_list = [x.name for x in bot.commands]
    if not args:
        help_embed.add_field(
            name="List of supported commands:",
            value="\n".join([str(i+1)+". "+x.name for i,x in enumerate(bot.commands)]),
            inline=False
        )
        help_embed.add_field(
            name="Details",
            value="Type `.help <command name>` for more details about each command.",
            inline=False
        )

    elif args in command_names_list:
        help_embed.add_field(
            name=args,
            value=bot.get_command(args).help
        )
    else:
        help_embed.add_field(
            name="Oh, no!",
            value="I didn't find command :("
        )
    await ctx.send(embed=help_embed)

I suppose you are using pycord as it is shown in the tags of the post.

The function taken as a decorator isn't bot.command() anymore, for a slash command but bot.slash_command()

It can takes as parameter a name , that will be displayed when typing the command on discord, a description , to provide details about the command, and for the general case, all the paramters taken by @bot.command()

Your script will look like this:

import discord
bot = discord.Bot()

@bot.slash_command()
async def help(ctx: discord.ApplicationContext,
           args: discord.Option(discord.SlashCommandOptionType.string, "args", required=False, default=None)):
    help_embed = discord.Embed(title="My Bot's Help!")
    command_names_list = [x.name for x in bot.commands]
    if not args:
        help_embed.add_field(
            name="List of supported commands:",
            value="\n".join([str(i+1)+". "+x.name for i,x in enumerate(bot.commands)]),
            inline=False
        )
        help_embed.add_field(
            name="Details",
            value="Type `.help <command name>` for more details about each command.",
            inline=False
        )

    elif args in command_names_list:
        help_embed.add_field(
            name=args,
            value=bot.get_command(args).help
        )
    else:
        help_embed.add_field(
            name="Oh, no!",
            value="I didn't find command :("
        )
    await ctx.send(embed=help_embed)

bot.run("YOUR TOKEN")

See: https://docs.pycord.dev/en/master/api.html?highlight=slash_command#discord.Bot.slash_command

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM