我有一个discord.py2.0按钮组件,我需要确保单击按钮的人是发起提示的人。但我不知道如何获得单击按钮的人,以便我可以比较它太ctx.author
。以下是我到目前为止所做的。
@bot.command()
async def prompt(ctx):
positive = Button(label="Yes", style=discord.ButtonStyle.green)
negative = Button(label="No", style=discord.ButtonStyle.red)
async def positive_callback(interaction):
if ctx.button == ctx.author: # ctx.button is not a real argument, that is what needs to be the user who clicks the button.
await interaction.response.edit_message(content=f"{ctx.author.mention} Here is some cake ❤", view=None)
positive.callback = positive_callback
view = View()
view.add_item(positive)
view.add_item(negative)
await ctx.send(content=f"{ctx.author.mention} Would you like to have some cake?", view=view)
1条答案
按热度按时间q3qa4bjr1#
经过更多的互联网搜索,我发现应该使用
interaction.user
而不是ctx.author
,就像这样,