This repository has been archived on 2022-06-13. You can view files and clone it, but cannot push or open issues or pull requests.
KassouBot/src/main.py

77 lines
2.6 KiB
Python
Raw Normal View History

2021-05-28 13:52:37 +02:00
print("Chargement des extensions & librairie...", end = " ")
2020-11-29 11:39:41 +01:00
2021-05-28 14:13:14 +02:00
import discord
from os import listdir, rename, getcwd
2021-05-28 14:03:34 +02:00
from discord_slash import SlashCommand
2020-11-29 11:39:41 +01:00
from discord.ext import commands
2021-06-03 12:21:00 +02:00
from utils.reminder import Reminder
2021-08-17 11:53:38 +02:00
from utils.core import load, addReaction
2021-08-02 12:50:38 +02:00
keys = load(["PREFIX", "TOKEN_DISCORD", "DEACTIVATE"])
2021-07-28 03:17:37 +02:00
customPrefix = keys["PREFIX"]
2020-11-29 11:39:41 +01:00
2021-05-07 16:44:47 +02:00
client = commands.Bot(command_prefix = customPrefix, case_insensitive = True, intents = discord.Intents.all())
slash = SlashCommand(client, sync_commands = True)
2020-11-29 11:39:41 +01:00
client.cogs_folder = "cogs"
2021-08-02 12:37:07 +02:00
if keys["DEACTIVATE"] != "None":
path = getcwd()
2021-08-02 12:37:07 +02:00
for file in keys["DEACTIVATE"]:
try:
rename(f"{path}/{client.cogs_folder}/{file}.py", f"{path}/{client.cogs_folder}/-{file}.py") # désactivation
except:
2021-08-02 12:50:08 +02:00
print(f"No file {file} found, check your \"DEACTIVATE\" variable.")
exit(1)
for file in listdir(client.cogs_folder):
2021-06-10 11:15:49 +02:00
if file.endswith(".py") and file.startswith("-") == False:
client.load_extension(f"{client.cogs_folder}.{file[:-3]}")
2021-05-28 13:52:37 +02:00
print("Terminé !")
2020-11-29 11:39:41 +01:00
@client.event
async def on_connect():
2021-08-17 11:35:25 +02:00
"""Triggered when the bot is connected to Discord"""
2021-05-28 13:52:37 +02:00
print(f"Connecté !")
2020-11-29 11:39:41 +01:00
@client.event
2021-06-24 13:17:20 +02:00
async def on_disconnect():
2021-08-17 11:35:25 +02:00
"""Triggered when the bot is disconnected to Discord"""
2021-06-24 13:17:20 +02:00
print(f"Déconnecté.")
@client.event
2021-06-24 22:48:10 +02:00
async def on_resumed():
2021-08-17 11:35:25 +02:00
"""Triggered when the bot is reconnected to Discord"""
2021-06-24 22:48:10 +02:00
print(f"Reconnecté !")
@client.event
2020-11-29 11:39:41 +01:00
async def on_ready():
2021-08-17 11:35:25 +02:00
"""Triggered when the bot is ready to operate"""
await client.change_presence(status = discord.Status.online, activity = discord.Activity(name = f"{customPrefix}help", type = discord.ActivityType.playing))
2021-06-08 22:15:09 +02:00
Reminder().creationTable()
2020-11-29 11:39:41 +01:00
print("Bot prêt.")
@client.event
async def on_command_error(ctx, error):
2021-08-17 11:35:25 +02:00
"""Triggered when a command enconter an error"""
if not ctx.invoked_with.startswith(customPrefix):
2020-11-29 11:39:41 +01:00
print(error)
2021-06-08 10:44:56 +02:00
if ctx.message:
2021-08-17 11:53:38 +02:00
await addReaction(ctx.message, 1)
2020-11-29 11:39:41 +01:00
@client.event
async def on_message(message):
2021-08-17 11:35:25 +02:00
"""Triggered a message is received"""
2020-11-29 11:39:41 +01:00
await client.process_commands(message)
if message.author == client.user:
return
2021-05-31 20:26:57 +02:00
"""informations concernant le bot lorsqu'il est mentionner"""
2020-11-29 11:39:41 +01:00
if client.user.mention == message.content.replace("!",""):
ctx = await client.get_context(message)
prefix = await client.get_prefix(message)
await ctx.send(f">>> Coucou !\nMon préfix est `{prefix}` et ma commande d'aide est `{prefix}help`")
2021-05-28 13:52:37 +02:00
print("Connexion à Discord...", end = " ")
2021-07-28 03:17:37 +02:00
client.run(keys["TOKEN_DISCORD"])