python Discord.py互动如何添加React

brvekthn  于 2023-08-02  发布在  Python
关注(0)|答案(1)|浏览(90)
@bot.tree.command()
@app_commands.describe(question="Give a title")
async def poll(interaction: discord.Interaction, question: str, choice_a: str = None, choice_b: str = None,
                 choice_c: str = None):
    emb = discord.Embed(title=f"{choice_a}\n{choice_b}\n{choice_c}\n",
                        type="rich")

    message = await interaction.response.send_message(f"**{question}**", embed=emb)

    await message.add_reaction('👍')

字符串
你好,这是我的代码,我想添加React,但这不工作。
我也试过:

await interaction.add_reaction('👍')
await interaction.message.add_reaction('👍')

wwtsj6pe

wwtsj6pe1#

await interaction.response.send_message()始终返回None
您可以通过使用await interaction.channel.send()来解决这个问题,它返回discord.Message,因此您可以使用add_reaction()

message = await interaction.channel.send(f"**{question}**", embed=emb)

    await message.add_reaction('👍')

字符串
晚了,但有更好的办法。使用interaction.original_response,我们可以得到interactionMessage对象,并从那里添加React。

await interaction.response.send_message(f"**{question}**", embed=emb)
msg = await interaction.original_response()
await msg.add_reaction('👍')

相关问题