-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
99 lines (78 loc) · 3.58 KB
/
Copy pathmain.py
File metadata and controls
99 lines (78 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import discord
from discord import app_commands
import pickle
# Ici j'importe les fichiers où l'on a défini les commandes
import fun
import mod
import utils
# Je définis les variables essentiels du Bot ici :
intents = discord.Intents.default()
intents.members = True
client = discord.Client(intents=intents)
tree = app_commands.CommandTree(client)
# Ici j'ajoute les commandes définient dans les autres fichiers :
for command in fun.fun_commands:
tree.command(name=command['name'], description=command['description'])(command['func'])
print(f"Command {command['name']} has been set up with the func {command['func']} !")
for command in mod.mod_commands:
tree.command(name=command['name'], description=command['description'])(command['func'])
print(f"Command {command['name']} has been set up with the func {command['func']} !")
for command in utils.utils_commands:
tree.command(name=command['name'], description=command['description'])(command['func'])
print(f"Command {command['name']} has been set up with the func {command['func']} !")
@client.event
async def on_ready():
"""
Cette commande s'éxecute lorsque le bot a démarré :
- Elle change son son statut + son activité;
- Elle synchronise "l'arbre" des commandes;
"""
await tree.sync()
await client.change_presence(activity=discord.Game("/game"), status=discord.Status.online)
print(f"We have logged in as {client.user}")
@client.event
async def on_member_join(member: discord.Member):
"""
Cette commande s'éxecute lorsqu'un membre rejoin le serveur :
- Paramètre 'member' : Les informations du membre en question;
"""
# Ici je récupère les données du fichier data/welcome_channel pour savoir où envoyer le message de bienvenue
try:
with open("data/welcome_channel", "rb") as file:
welcome_channels = pickle.Unpickler(file).load()
try:
if welcome_channels[member.guild.id] is not None:
welcome_embed = discord.Embed(title="**:tada: | Bienvenue !**",
description=f"Bienvenue à {member.mention} sur"
f" **{member.guild.name}** ! Tu es le"
f" **{member.guild.member_count}eme** "
f"membre !",
color=discord.Color.red())
welcome_embed.set_thumbnail(url='https://cdn3.emoji.gg/emojis/6286_tada_animated.gif')
await client.get_channel(welcome_channels[member.guild.id]).send(embed=welcome_embed)
except KeyError:
pass
except EOFError:
pass
try:
with open("data/auto_roles", "rb") as file:
auto_roles = pickle.Unpickler(file).load()
for role_id in auto_roles[member.guild.id]:
role = member.guild.get_role(role_id)
await member.add_roles(role)
except EOFError:
pass
@tree.error
async def on_command_error(interaction, error):
"""
Cette commande s'éxecute lorsque le Bot reçoit une erreur :
- Pour l'instant elle ne traite que les erreurs de permissions;
"""
if isinstance(error, app_commands.MissingPermissions):
embed = discord.Embed(title=":x: | Tu n'as pas la permission d'utiliser cette commande !", color=discord.Color.red())
await interaction.response.send_message(embed=embed, ephemeral=True)
return
raise error
TOKEN = ""
print("Launch of the Client...")
client.run(TOKEN)