我正在制作一个投票机器人,现在我想知道如何计算 react 并找到获胜者答案,我已经尝试了很多,但我无法做到。有谁知道吗?
embed = discord.Embed(title="¡Es momento de tomar una encuesta!", colour=discord.Colour(0x3e038c))
embed.add_field(name='Autor de la encuesta', value=f'{ctx.author}')
embed.add_field(name='Pregunta:', value=f'{pregunta}')
msg = await ctx.send(embed=embed)
await msg.add_reaction(str('🔺'))
await msg.add_reaction(str('🔻'))
最佳答案
要实现您想要的效果,您只需检查 message.reactions
参数的length
。
示例:
from discord.utils import get
async def check_winner(self, ctx, messageid: int):
# ...
# Some code here
message = await ctx.fetch_message(messageid)
reaction = get(message.reactions, emoji='your emoji here')
num_reactions = reaction.count
# More code here
# ...
在检查投票获胜者的命令中,您首先需要检索投票的message_id,然后将其作为参数传递给您的命令,以便您可以检索消息
对象并找到附加到它的 react 。
引用文献:
关于python - 计算discord.py上的 react ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65804415/