如何获得表情符号的id?

2024-10-01 15:33:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图在一条消息的反应中获得表情符号的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")

上下文:我在玩一个不和谐的游戏,其中一个机器人发送一个带有角色名称的嵌入,在这个嵌入上,机器人自动添加一个反应。我想要的是得到机器人反应的id,并用id添加相同的值


Tags: inclientsendid消息messageget机器人
1条回答
网友
1楼 · 发布于 2024-10-01 15:33:49

你不需要再让表情符号做出反应。您只需添加表情类的反应即可。
我还建议您稍等片刻,然后再次获取消息,因为不会立即对消息对象产生反应

@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")

请参阅^{}对象

相关问题 更多 >

    热门问题