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

85 lines
4.4 KiB
Python
Raw Normal View History

2020-10-14 02:50:24 +02:00
print("Lancement du bot de la licence")
import discord
from discord.ext import commands
from setup import token
2020-10-14 03:23:14 +02:00
# 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)
2020-10-14 02:50:24 +02:00
client = commands.Bot(command_prefix = ".", case_insensitive = True, intents = discord.Intents.all())
@client.event
async def on_connect():
print("Connecté.")
print("Chargement des extensions & librairie...")
client.load_extension("cogs.commands")
client.load_extension("cogs.help")
2020-10-14 02:50:24 +02:00
2020-10-14 03:23:14 +02:00
# le status du bot
2020-10-14 02:50:24 +02:00
@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",
2020-10-20 15:06:08 +02:00
type = discord.ActivityType.competing))
print("Bot prêt.")
2020-10-14 02:50:24 +02:00
@client.event
2020-10-14 03:23:14 +02:00
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
2020-10-14 03:02:43 +02:00
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)
2020-10-14 02:50:24 +02:00
2020-10-14 03:23:14 +02:00
# meme systeme qu'au dessus sauf que c'est plus compliqué de choppé le membre pour lui retirer son rôle
2020-10-14 02:50:24 +02:00
@client.event
async def on_raw_reaction_remove(payload):
2020-10-14 03:02:43 +02:00
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)
2020-10-14 02:50:24 +02:00
2020-10-14 03:23:14 +02:00
# pour lancer le bot
2020-10-14 02:50:24 +02:00
client.run(token)