因此,我希望机器人在用户对带有特定表情符号的消息做出反应时自动分配角色。但是我的代码不起作用。我该如何解决???
@client.event
async def on_raw_reaction_add(payload):
messgae_id = payload.message_id
if messgae_id == "759765065380659261":
user = payload.user_id
for roles in user.roles:
if roles in DefaultRoles:
return
if payload.emoji.name == "smiling_imp":
role = discord.utils.get(user.server.roles, name = "Demon")
await user.add_role(user, role)
答案 0 :(得分:0)
对于标准的不和谐表情符号,您不能使用名称,而需要使用unicode符号。 所以不是'smiling_imp'而是'?'
要获取unicode表情符号,可以在发送前在标准表情符号之前添加\(不要在移动设备上使用它)
在Discord.py 1.0之后,“服务器”更改为“公会”
if message_id == ________________:
# Find the guild name
guild_id = payload.guild_id
guild = discord.utils.find(lambda g :g.id == guild_id, client.guilds)
# Get your guild role
if payload.emoji.name == '?':
role = discord.utils.get(guild.roles, name='Demon')
# Find the member you are trying to assign role to
member = discord.utils.find(lambda m : m.id == payload.user_id, guild.members)
# Assign role
await member.add_roles(role)