discord.py通过命令发送一条消息,该命令在设定的时间后计算有多少人“投票”了一次反应(正常的表情符号)

时间:2020-08-29 01:14:24

标签: discord.py

我已经尝试了好几天(甚至被要求没有成功)来使响应依赖于消息。我正在处理的命令是表决命令,该命令在一定时间后会通过精确计算一个反应在另一个反应中的投票数来自动写入结果。 我想使用自定义表情符号,但我什至不能,甚至尝试使用普通表情符号,我什至不计算它们,我也不知道该怎么做。 这是我用于测试的代码,是否有可能我想通过添加自定义表情符号来解决该问题。

@client.command(aliases=["cr"])
@commands.has_permissions(administrator=True)
async def conteggio_reazioni(ctx, *, proposta):
    message = await ctx.send(proposta)
    favore = get(message.reactions, emoji="?")
    contro = get(message.reactions, emoji="?")
    flore = get(message.reactions, emoji="?")
    await message.add_reaction("?")
    await message.add_reaction("?")
    await message.add_reaction("?")
    await asyncio.sleep(10)
    print('temposcaduto')
    await ctx.send(f"{favore.count} a favore , {contro.count} contro e {flore.count} astenuti")

1 个答案:

答案 0 :(得分:1)

您必须使用fetch_message()再次获取消息并获得新的反应

@client.command(aliases=["cr"])
@commands.has_permissions(administrator=True)
async def conteggio_reazioni(ctx, *, proposta):
    message = await ctx.send(proposta)
    await message.add_reaction("?")
    await message.add_reaction("?")
    await message.add_reaction("?")
    await asyncio.sleep(10)
    message = await ctx.channel.fetch_message(message.id)
    thumbsup = len([await i.users().flatten() for i in message.reactions if str(i.emoji) == "?"][0])
    thumbsdown = len([await i.users().flatten() for i in message.reactions if str(i.emoji) == "?"][0])
    neutral = len([await i.users().flatten() for i in message.reactions if str(i.emoji) == "?"][0])
    
    print('temposcaduto')
    await ctx.send(f"{thumbsup} a favore , {thumbsdown} contro e {neutral} astenuti")