【问题标题】:how can i get the id of an emoji in reaction?我怎样才能得到一个表情符号的ID?
【发布时间】:2021-08-17 00:00:51
【问题描述】:

我正在尝试在消息的反应中获取表情符号的 ID,但我不知道该怎么做。

@client.event 
async def on_message(message):
    channal = client.get_channel(825523364844142601)
    embeds = message.embeds
    for embed in embeds:
        if embed.author.name in wishlist:
            reaction = get(message.reactions)
            print(reaction)
            await channal.send("yes")
        else:
            await channal.send("false")

context : 我在玩一个不和谐的游戏,机器人发送一个带有角色名称的嵌入,在这个嵌入上,机器人会自动添加一个反应。我想要的是获取机器人反应的 id 并添加相同的 id

【问题讨论】:

  • get() 定义在哪里?

标签: python discord discord.py emoji


【解决方案1】:

您无需再次获取表情符号即可做出反应。您可以添加来自 Emoji 类的反应。
我还建议稍等片刻,然后再次获取消息,因为消息对象不会立即做出反应。

@client.event 
async def on_message(message):
    channal = client.get_channel(825523364844142601)
    embeds = message.embeds
    for embed in embeds:
        if embed.author.name in wishlist:
            await asyncio.sleep(1.0) # Give time for reaction to update on cache
            message = await message.channel.fetch_message(message.id) # Update message object 
            reaction = message.reactions[0] # Get first reaction of a message
            emoji = reaction.emoji
            emoji_id = emoji.id
            await message.add_reaction(emoji) # You can just add with emoji, you don't need to get emoji again
            await channal.send("yes")
        else:
            await channal.send("false")

查看discord.Reaction 对象。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-24
    • 1970-01-01
    • 2015-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-15
    • 2015-06-08
    相关资源
    最近更新 更多