[英]How can I make a embed help slash command using pycord?
how can I make the embed help command that uses slash commands?如何制作使用斜杠命令的嵌入帮助命令?
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.我想您正在使用
pycord
,因为它显示在帖子的标签中。
The function taken as a decorator isn't bot.command()
anymore, for a slash command but bot.slash_command()
用作装饰器的 function 不再是
bot.command()
,对于斜杠命令,而是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()
它可以将
name
作为参数,在 discord 上键入命令时将显示该参数,a description
以提供有关命令的详细信息,对于一般情况, @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
请参阅:
https://docs.pycord.dev/en/master/api.html?highlight=slash_command#discord.Bot.slash_command
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.