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
2021-08-02 12:50:38 +02:00

68 lines
2.2 KiB
Python

print("Chargement des extensions & librairie...", end = " ")
import discord
from os import listdir, rename, getcwd
from discord_slash import SlashCommand
from discord.ext import commands
from utils.reminder import Reminder
from utils.core import load
keys = load(["PREFIX", "TOKEN_DISCORD", "DEACTIVATE"])
customPrefix = keys["PREFIX"]
client = commands.Bot(command_prefix = customPrefix, case_insensitive = True, intents = discord.Intents.all())
slash = SlashCommand(client, sync_commands = True)
if keys["DEACTIVATE"] != "None":
path = getcwd()
for file in keys["DEACTIVATE"]:
try:
rename(f"{path}/cogs/{file}.py", f"{path}/cogs/-{file}.py") # désactivation
except:
print(f"No file {file} found, check your \"DEACTIVATE\" variable.")
exit(1)
for file in listdir("cogs"):
if file.endswith(".py") and file.startswith("-") == False:
client.load_extension(f"cogs.{file[:-3]}")
print("Terminé !")
@client.event
async def on_connect():
print(f"Connecté !")
@client.event
async def on_disconnect():
print(f"Déconnecté.")
@client.event
async def on_resumed():
print(f"Reconnecté !")
@client.event
async def on_ready():
await client.change_presence(status = discord.Status.online, activity = discord.Activity(name = f"{customPrefix}help", type = discord.ActivityType.playing))
Reminder().creationTable()
print("Bot prêt.")
@client.event
async def on_command_error(ctx, error):
if not ctx.invoked_with.startswith(customPrefix):
print(error)
if ctx.message:
await ctx.message.add_reaction(emoji = '')
@client.event
async def on_message(message):
await client.process_commands(message)
if message.author == client.user:
return
"""informations concernant le bot lorsqu'il est mentionner"""
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`")
print("Connexion à Discord...", end = " ")
client.run(keys["TOKEN_DISCORD"])