【问题标题】:How to count the emojis and display them in a discord bot reaction?如何计算表情符号并在不和谐的机器人反应中显示它们?
【发布时间】:2020-07-18 03:31:34
【问题描述】:
for second in range(60):
    message_id = await message.channel.fetch_message(message.id)
    for reaction in message_id.reactions:
        thumbs_up_count = 0
        thumbs_down_count = 0
        if str(reaction.emoji) == '????':
            thumbs_up_count = reaction.emoji.count
        if str(reaction.emoji) == '????':
            thumbs_down_count = reaction.emoji.count
        await message.edit(content=("**----POLL----** \n \n**Green Today?** :thumbsup: {} \n \n**Red Today?**   :thumbsdown: {}".format(thumbs_up_count,thumbs_down_count)))
        await asyncio.sleep(3)

这是我的代码,它进行民意调查,人们的反应是竖起大拇指或大拇指向下。然后它会在投票时不断编辑消息。代码效率不高,但我没有看到逻辑错误在哪里。它根本不计算表情符号并显示 0。

【问题讨论】:

    标签: python discord


    【解决方案1】:

    这是因为您总是用 reaction.emoji.count 带来的值替换 thumbs_up_count, thumbs_down_count 值,所以您可以尝试如下:

    for second in range(60):
        message_id = await message.channel.fetch_message(message.id)
        for reaction in message_id.reactions:
            thumbs_up_count = 0
            thumbs_down_count = 0
            if str(reaction.emoji) == '?':
                thumbs_up_count += reaction.emoji.count
            if str(reaction.emoji) == '?':
                thumbs_down_count += reaction.emoji.count
            await message.edit(content=("**----POLL----** \n \n**Green Today?** :thumbsup: {} \n \n**Red Today?**   :thumbsdown: {}".format(thumbs_up_count,thumbs_down_count)))
            await asyncio.sleep(3)
    

    请注意,在这两种情况下,我都将 = 替换为 +=

    希望对你有帮助:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-11
      • 2021-05-14
      • 2019-02-13
      • 2021-05-24
      • 2020-06-29
      • 1970-01-01
      • 2020-07-10
      • 2020-07-30
      相关资源
      最近更新 更多