adding a second server for the reaction adding roles

This commit is contained in:
Mylloon 2021-09-16 12:56:16 +02:00
parent a3820ec569
commit abd2ffb116

View file

@ -14,15 +14,21 @@ 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: 882616261626970112, # elephant - l1
882783004697714789: 882616188830629998, # gorilla - l2
882783004416675881: 882616082022670387, # cat - - l3
882783005108744202: 882616475918147654, # rabbit - visiteurs
882783004911624212: 882616714133635093 # dog - alumni
self.messageDictAndEmojiToRoles = {
882785207235788800:
{
882783004706095194: 882616261626970112, # elephant - l1
882783004697714789: 882616188830629998, # gorilla - l2
882783004416675881: 882616082022670387, # cat - - l3
882783005108744202: 882616475918147654, # rabbit - visiteurs
882783004911624212: 882616714133635093 # dog - alumni
},
888001335105036329:
{
"1": 887999417892880474, # 1 - étudiant
"2": 887999473513549845, # 2 - professeur
}
}
@commands.Cog.listener()
async def on_member_join(self, member):
"""Triggered when a member join a guild"""
@ -118,25 +124,27 @@ class ConfrerieDuKassoulait(commands.Cog):
for _ in range(0, 2):
await Internet(self.client)._cat(self, await self.client.get_context(message))
# encore un autre serveur
# encore d'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:
try:
self.emoji_to_role[payload.emoji.id]
except KeyError:
return
await payload.member.add_roles(payload.member.guild.get_role(self.emoji_to_role[payload.emoji.id]))
await payload.member.add_roles(payload.member.guild.get_role(self.messageDictAndEmojiToRoles[payload.message_id][payload.emoji.id]))
except:
await payload.member.add_roles(payload.member.guild.get_role(self.messageDictAndEmojiToRoles[payload.message_id][str(payload.emoji)]))
except KeyError:
return
@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
try:
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)
await member.remove_roles(guild.get_role(self.emoji_to_role[payload.emoji.id]))
try: # essaie avec l'emoji ID
await member.remove_roles(guild.get_role(self.messageDictAndEmojiToRoles[payload.message_id][payload.emoji.id]))
except: # essaie avec l'emoji
await member.remove_roles(guild.get_role(self.messageDictAndEmojiToRoles[payload.message_id][str(payload.emoji)]))
except KeyError:
return