This repository has been archived on 2022-03-31. You can view files and clone it, but cannot push or open issues or pull requests.
bot-licence/main.py

94 lines
No EOL
4.6 KiB
Python
Executable file

print("Lancement du bot de la licence")
import discord
from discord.ext import commands
from setup import token
# on décide du prefix
# on dit d'ignorer les majuscules/minuscules quand on tape une commande
# plus d'infos sur l'intent ici : https://discordpy.readthedocs.io/en/latest/intents.html (j'ai pas encore tout compris c'est nouveau)
client = commands.Bot(command_prefix = ".", case_insensitive = True, intents = discord.Intents.all())
@client.event
async def on_connect():
print("Le bot est en ligne.")
# le status du bot
@client.event
async def on_ready():
await client.change_presence(status = discord.Status.online, activity = discord.Activity(name = "https://code.up8.edu/Anri/bot-licence",
type = discord.ActivityType.competing))
print("Bot chargé à 100%.")
@client.event
async def on_raw_reaction_add(payload): # check toutes les nouvelles réactions
if payload.message_id == 765470422149365760: # on check si on réagis au message que l'on veut
# en fonction de la réaction on donne le role
if payload.emoji.name == '🟡':
role = discord.utils.get(payload.member.guild.roles, name="L1A1")
await payload.member.add_roles(role)
if payload.emoji.name == '🟠':
role = discord.utils.get(payload.member.guild.roles, name="L1A2")
await payload.member.add_roles(role)
if payload.emoji.name == '🔵':
role = discord.utils.get(payload.member.guild.roles, name="L1B1")
await payload.member.add_roles(role)
if payload.emoji.name == '🟣':
role = discord.utils.get(payload.member.guild.roles, name="L1B2")
await payload.member.add_roles(role)
if payload.emoji.name == '🟤':
role = discord.utils.get(payload.member.guild.roles, name="L1C1")
await payload.member.add_roles(role)
if payload.emoji.name == '🟢':
role = discord.utils.get(payload.member.guild.roles, name="L1C2")
await payload.member.add_roles(role)
# meme systeme qu'au dessus sauf que c'est plus compliqué de choppé le membre pour lui retirer son rôle
@client.event
async def on_raw_reaction_remove(payload):
if payload.message_id == 765470422149365760:
if payload.emoji.name == '🟡':
guild = discord.utils.find(lambda g : g.id == payload.guild_id, client.guilds)
member = discord.utils.find(lambda m: m.id == payload.user_id, guild.members)
role = discord.utils.get(guild.roles, name="L1A1")
await member.remove_roles(role)
if payload.emoji.name == '🟠':
guild = discord.utils.find(lambda g : g.id == payload.guild_id, client.guilds)
member = discord.utils.find(lambda m: m.id == payload.user_id, guild.members)
role = discord.utils.get(guild.roles, name="L1A2")
await member.remove_roles(role)
if payload.emoji.name == '🔵':
guild = discord.utils.find(lambda g : g.id == payload.guild_id, client.guilds)
member = discord.utils.find(lambda m: m.id == payload.user_id, guild.members)
role = discord.utils.get(guild.roles, name="L1B1")
await member.remove_roles(role)
if payload.emoji.name == '🟣':
guild = discord.utils.find(lambda g : g.id == payload.guild_id, client.guilds)
member = discord.utils.find(lambda m: m.id == payload.user_id, guild.members)
role = discord.utils.get(guild.roles, name="L1B2")
await member.remove_roles(role)
if payload.emoji.name == '🟤':
guild = discord.utils.find(lambda g : g.id == payload.guild_id, client.guilds)
member = discord.utils.find(lambda m: m.id == payload.user_id, guild.members)
role = discord.utils.get(guild.roles, name="L1C1")
await member.remove_roles(role)
if payload.emoji.name == '🟢':
guild = discord.utils.find(lambda g : g.id == payload.guild_id, client.guilds)
member = discord.utils.find(lambda m: m.id == payload.user_id, guild.members)
role = discord.utils.get(guild.roles, name="L1C2")
await member.remove_roles(role)
# on importe les modules complémentaires situé dans cogs/
try:
client.load_extension("cogs.commands")
except Exception as error:
print(error)
client.remove_command("help")
try:
client.load_extension("cogs.help")
except Exception as error:
print(error)
# pour lancer le bot
client.run(token)