[英]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.