我正在制作一个discord bot,它查询Spotify API,并将结果作为discord嵌入返回。它不是在多条消息中发送多个结果,而是在嵌入式中发送一条显示一个结果的消息,用户可以通过与⬅或➡表情符号反应来导航。
当机器人检测到on_reaction_add事件
时,它会检测该反应是⬅表情还是➡表情,并编辑具有该反应的消息以更新嵌入。
然而,使用我的方法,每当有人将⬅或➡的反应添加到机器人的其他消息中时,机器人将对其进行编辑,而我不知道如何让机器人记住用户给出的查询,然后使用相同的查询(但偏移量不同)再次获取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)
使用reaction.message
。它检测被响应的消息。