仅检测由机器人在discord.py中发送的特定消息的反应

时间:2020-05-21 12:33:40

标签: python discord python-3.7 discord.py

我正在制作一个Discord机器人,该机器人查询Spotify API并以Discord嵌入的形式返回结果。它不会在多个消息中发送多个结果,而是发送一条在嵌入中显示一个结果的消息,用户可以通过与⬅️表情符号或➡️表情符号进行反应来浏览。
当漫游器检测到on_reaction_add event时,它会检测反应是the️还是or️表情符号,并编辑具有该反应的消息以更新嵌入。
但是,用我的方法,每当有人向bot的其他消息添加⬅️或➡️反应时,该bot都会对其进行编辑,而我无法弄清楚如何让bot记住用户给出的查询,然后获取Spotify API再次使用相同的查询,但具有不同的偏移量。
我的问题是,如何让机器人仅在嵌入了Spotify的邮件上检测⬅️和➡️反应,以及如何让机器人记住邮件中的查询内容?
这是我正在使用的代码:

@client.event
async def on_message(message):
    #if the spotify command is triggered
        #fetch from the API
        spotifyEmbed = discord.Embed(title=resultName, ...)
        spotifyEmbed.set_image(url=spotifyImgUrl)
        spotifyMessage = await message.channel.send(embed=spotifyEmbed)
        await spotifyMessage.add_reaction("⬅️")
        await spotifyMessage.add_reaction("➡️")

@client.event
async def on_reaction_add(reaction, user):
    if user != client.user:
        if str(reaction.emoji) == "➡️":
            #fetch new results from the Spotify API
            newSearchResult = discord.Embed(...)
            await reaction.message.edit(embed=newSearchResult)
        if str(reaction.emoji) == "⬅️":
            #fetch new results from the Spotify API
            newSearchResult = discord.Embed(...)
            await reaction.message.edit(embed=newSearchResult)

1 个答案:

答案 0 :(得分:0)

使用reaction.message。它检测到响应的消息。

相关问题