使用discord组件的discord.py帮助命令

2024-06-01 13:12:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用discord组件库的“SelectOption”组件修改我的help命令。以下是代码:-

@bot.command()
async def help(ctx):
  embed_main = discord.Embed(title = "Help!", color = discord.Color.random())
  await ctx.send(
    embed=embed_main,
    components = [
      Select(placeholder="Make A Choice!", options=[SelectOption(emoji="🛠", label="Moderation", value="A", description="Get Help On Moderation")])
      ]
  )
  interaction = await bot.wait_for("select_option", check=lambda i: i.component[0].value == "A")
  await interaction.respond(
    embed = discord.Embed(title = "🛠 Moderation Commands", color = discord.Color.random())
    embed.add_field(name = "Type `tnj.help <command name> for more info on it", value = "`kick`\n `ban`\n `unban`\n `mute`\n `unmute`\n `purge`")
    )

每件事都能正常工作,但它给出了一个语法错误,并在这一行上写着“expected’”:

embed.add_field(name = "Type `tnj.help <command name> for more info on it", value = "`kick`\n `ban`\n `unban`\n `mute`\n `unmute`\n `purge`")

我不知道我做错了什么,任何帮助都将不胜感激谢谢


Tags: nameforvaluemainbothelp组件embed
1条回答
网友
1楼 · 发布于 2024-06-01 13:12:47

很难猜测您的意图,但此代码可能更接近您想要做的事情:

embed = discord.Embed(title = "🛠 Moderation Commands", color = discord.Color.random())
await interaction.respond(
    embed,
    embed.add_field(name = "Type `tnj.help <command name> for more info on it", value = "`kick`\n `ban`\n `unban`\n `mute`\n `unmute`\n `purge`")
    )

这假设embed.add_field()返回的值适合作为调用interaction.respond()的第二个参数

相关问题 更多 >