【问题标题】:Implementing role reactions using native discord emojis instead of custom discord emojis(python)使用本机不和谐表情符号而不是自定义不和谐表情符号(python)实现角色反应
【发布时间】:2020-07-10 06:47:15
【问题描述】:

我一直致力于在 python 中编写我自己的 discord 机器人,并且我一直在尝试以某种方式实现对特定消息的反应,你会给你一个特定的角色吗?我想出了如何让它工作自定义不和谐表情符号,但我正在努力让它与原生不和谐表情符号一起工作。我知道我应该尝试以某种方式使用表情符号的 unicode,但我就是想不通

#roles for hemisphere and native fruit
#first part - emoji id, second part - role id
#CUSTOM EMOJIS
hemisphere = {693662576936222811:[693663054788821092],
693662585953714256:[693663114914168913]
            }
#NATIVE DISCORD EMOJIS
native_fruit = {693711698082660427:[693711520953270293],
693711724024430633:[693711530197516289],
693711811312353330:[693711572312391721],
693711739744813056:[693711538623742042],
693711786582474752:[693711553257799720]
                }
hemisphere_id=693914783979667506
native_fruit_id=693914786773205103

#add roles
@bot.event
async def on_raw_reaction_add(reaction):
    if reaction.user_id==bot.user.id:
        return
    if not ((reaction.emoji.id in hemisphere) or (reaction.emoji.id in native_fruit)):
        return


    guild = await bot.fetch_guild(reaction.guild_id)
    user = await guild.fetch_member(reaction.user_id)

#CUSTOM EMOJIS
    if reaction.message_id == hemisphere_id:
        emojiid = hemisphere.get(reaction.emoji.id)
        id =emojiid[0]
        await user.add_roles(guild.get_role(id))
#NATIVE DISCORD EMOJIS
    elif reaction.message_id == native_fruit_id:
        emojiid = native_fruit.get(reaction.emoji.id)
        id = emojiid[0]
        await user.add_roles(guild.get_role(id))        
    else:
        return

我一般是 python 新手,所以我无法弄清楚如何前进

【问题讨论】:

  • 您能否更具体地说明问题是什么?

标签: python unicode discord


【解决方案1】:

对于原生表情符号,您必须粘贴实际的表情符号图标而不是 ID。 您可以通过在 discord 中输入 \:emoiji_id: 并将 emoji_id 替换为表情符号的 ID 来获取它。 例如,cucumber 是不和谐的原生表情符号,要在你的代码中使用它,你必须在不和谐中输入\:cucumber:,它会返回?。然后,您可以将 ? 复制并粘贴到您的代码中以代替 native_fruit_id。您也可以继续 https://getemoji.com/ 并从那里复制和粘贴。希望对您有所帮助!

【讨论】:

    猜你喜欢
    • 2020-04-30
    • 2018-08-26
    • 1970-01-01
    • 2021-05-24
    • 2021-12-23
    • 2021-05-14
    • 2021-04-19
    • 2022-07-14
    • 2021-05-06
    相关资源
    最近更新 更多