I'm a little ridiculous, so I'll make a note of it.
@client.event
async def on_raw_reaction_add(payload):
if payload.message_id ==Message ID you want to have a reaction:
checked_emoji = payload.emoji.id
guild_id = payload.guild_id
guild = discord.utils.find(lambda g: g.id == guild_id, client.guilds)
if checked_emoji ==Reaction ID:
role = guild.get_role(Job title ID)
await payload.member.add_roles(role)
@client.event
async def on_raw_reaction_remove(payload):
if payload.message_id ==Message ID you want to have a reaction:
checked_emoji = payload.emoji.id
guild_id = payload.guild_id
guild = discord.utils.find(lambda g: g.id == guild_id, client.guilds)
if checked_emoji ==Reaction ID:
role = guild.get_role(Job title ID)
member = guild.get_member(payload.user_id)
await member.remove_roles(role)
For those who have a job title
await payload.member.add_roles(role)
I can go, but the one to erase is
member = guild.get_member(payload.user_id)
await member.remove_roles(role)
You need to get member
once.
If a reaction is added, member
will be included in payload
, but when the reaction is deleted, member
does not exist.
https://discordpy.readthedocs.io/en/latest/api.html?highlight=reaction%20remove#discord.RawReactionActionEvent.member
await payload.member.remove_roles(role)
And write
AttributeError: 'NoneType' object has no attribute 'remove_roles'
I hope that people who are angry and angry will find a solution after seeing this article.
Recommended Posts