【发布时间】:2021-08-07 00:07:25
【问题描述】:
我正在使用 discord-components 库的“SelectOption”组件改进我的帮助命令。这是代码:-
@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`")
)
一切正常,但它给出了一个语法错误,并在这一行显示“预期的')'”:-
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`")
我不知道我做错了什么,任何帮助将不胜感激。
【问题讨论】:
-
在 Python 中,赋值是纯粹的语句,不能用于需要表达式的地方。
embed = discord.Embed(title = "???? Moderation Commands", color = discord.Color.random())是一个语句,但在需要表达式的地方使用(作为interaction.respond()调用的参数)。这会导致SyntaxError。此外,如果您打算将这两行用作调用的两个参数,则需要用逗号分隔它们。
标签: python discord discord.py