python - 计算discord.py上的 react

标签 python discord discord.py

我正在制作一个投票机器人,现在我想知道如何计算 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/

相关文章:

Python googletrans编码奇怪的字符

python - 不能使用 bot.run ('TOKEN' ) - Discord.py

discord.py - Discord API - 从 channel 获取日期之前的消息

python - 命令不在 discord.py 2.0 中运行 - 没有错误,但在 discord.py 1.7.3 中运行

python - SQL 到 SQLAlchemy 的翻译

Python TCP 端口扫描器

python - 无法使用pip安装nltk

javascript - 如何测试表情符号在discord.js 中是否有动画

python - 为什么 Heroku 不喜欢我的文件夹结构?

javascript - 有什么方法可以从浏览器开发控制台获取我的不和谐 token ?