-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.py
53 lines (39 loc) · 1.46 KB
/
index.py
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
import os
import json
from utils import database
from disnake.ext import commands
from utils import translations
async def before_invoke(ctx):
if ctx.guild:
ctx.config = await ctx.bot.db.get_config(ctx.guild.id)
ctx.lang = ctx.config["locale"]
else:
ctx.lang = ctx.bot.c["default_locale"]
ctx.t = translations.Translate(lang=ctx.lang, translate_module=ctx.bot.translations).t
if __name__ == "__main__":
with open("config.json") as conf:
c = json.load(conf)
bot = commands.AutoShardedBot(command_prefix=c["prefix"])
bot.c = c
for cog in os.listdir("./cogs"):
if not cog.endswith(".py"):
continue
print(f"Loading Cog: {cog[:-3]}")
try:
bot.load_extension(f"cogs.{cog[:-3]}")
print(f"[OK] Loaded cog: {cog}")
except SyntaxError as e:
print(f"[Fail] Failed to load {cog}: Syntax error \n\t{e}")
except ImportError as e:
print(f"[Fail] Failed to import cog {cog}: \n\t{e}")
bot.db = database.Database(bot) # Initialisation de la base de données
bot.translations = translations.Translations("./translations/")
bot.translations.load_translations()
bot.t = bot.translations.t
bot.before_invoke(before_invoke)
bot.run(bot.c["token"])
@bot.event
async def on_message(message):
if not bot.is_ready() or message.author.bot:
return
await bot.process_commands(message)