繁体   English   中英

这个帮助命令代码有什么问题? 我正在使用 pycord

[英]what's wrong this this help command code? I'm using pycord

它只是响应所有命令,但是当我键入 /help 命令时

它说:

应用程序没有响应

这是我的代码:

@bot.slash_command(name="help", description="Get some help.")
async def help(ctx, args: Option(str, required=False)):
    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.respond(embed=help_embed)

如果你想显示你创建的命令的描述,你必须使用description属性,因为没有help属性。

这是你应该得到的:

import discord
from discord import Option

bot = discord.Bot()


@bot.slash_command(name="help", description="Get some help.")
async def help(ctx, args: Option(str, required=False)):
    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).description
        )
    else:
        help_embed.add_field(
            name="Oh, no!",
            value="I didn't find command :("
        )
   await ctx.respond(embed=help_embed)

https://docs.pycord.dev/en/master/api.html?highlight=slashcommand#discord.SlashCommand

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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