我一直在用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的新手,所以我很难弄清楚如何前进
答案 0 :(得分:0)
对于本机表情符号,您必须粘贴实际的表情符号图标而不是ID。
您可以通过在和谐中输入\:emoiji_id:
并将emoji_id
替换为表情符号的ID来获得它。
例如,cucumber
是不和谐的本机表情符号,要在您的代码中使用它,您必须在不和谐中键入\:cucumber:
,它将返回?。然后,您可以将copy复制并粘贴到代码中,以代替native_fruit_id
。您还可以继续https://getemoji.com/并从那里复制并粘贴。希望有帮助!