Add custom role emoji reaction

This commit is contained in:
Mylloon 2021-09-02 02:50:57 +02:00
parent 559dc66559
commit 8c88e940e0

View file

@ -14,6 +14,14 @@ class ConfrerieDuKassoulait(commands.Cog):
"""Unique pour le serveur Discord "La confrérie du Kassoulait"."""
def __init__(self, client):
self.client = client
self.role_message_id = 882785207235788800 # ID of the message that can be reacted to to add/remove a role.
self.emoji_to_role = {
882783004706095194: "L1", # elephant
882783004697714789: "L2", # gorilla
882783004416675881: "L3", # cat
882783005108744202: "Visiteurs", # rabbit
882783004911624212: "Alumni" # dog
}
@commands.Cog.listener()
async def on_member_join(self, member):
@ -109,3 +117,28 @@ class ConfrerieDuKassoulait(commands.Cog):
if message.content.lower() in chats:
for _ in range(0, 2):
await Internet(self.client)._cat(self, await self.client.get_context(message))
# encore un autre serveur
@commands.Cog.listener()
async def on_raw_reaction_add(self, payload):
"""Add a role when a special reaction to a special message is added."""
if payload.message_id == self.role_message_id:
try:
self.emoji_to_role[payload.emoji.id]
except KeyError:
return
role = discord.utils.get(payload.member.guild.roles, name = self.emoji_to_role[payload.emoji.id])
await payload.member.add_roles(role)
@commands.Cog.listener()
async def on_raw_reaction_remove(self, payload):
"""Remove a role when a special reaction to a special message is removed."""
if payload.message_id == self.role_message_id:
try:
self.emoji_to_role[payload.emoji.id]
except KeyError:
return
guild = discord.utils.find(lambda g: g.id == payload.guild_id, self.client.guilds)
member = discord.utils.find(lambda m: m.id == payload.user_id, guild.members)
role = discord.utils.get(guild.roles, name = self.emoji_to_role[payload.emoji.id])
await member.remove_roles(role)