-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
58 lines (42 loc) · 2.11 KB
/
Copy pathbot.py
File metadata and controls
58 lines (42 loc) · 2.11 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
"""
----------------------------------------------------------------------------
This file is the main entry point for the bot. It initializes the bot, initializes the DB files if needed, loads all cogs, and starts the bot.
this script should be run to start the bot, and it will handle everything else. The cogs are located in the Cogs folder, and they will be loaded automatically when the bot starts. If you want to add a new cog, simply create a new .py file in the Cogs folder and it will be loaded automatically when the bot starts.
----------------------------------------------------------------------------
"""
import discord
from discord.ext import commands
import os
import Utilities.botConfig as botConfig
from Utilities.databaseManager import init_db, GUILD_IDS, init_module_db
from Cogs.Modules.Core.defaultModules import enable_defaults_for_existing_guilds
class MyClient(commands.Bot):
def __init__(self):
super().__init__(
command_prefix="!",
intents=botConfig.intents,
application_id=botConfig.APPLICATION_ID
)
async def setup_hook(self):
await init_db()
await init_module_db()
await enable_defaults_for_existing_guilds(self)
await self.load_all_cogs("./Cogs")
async def load_all_cogs(self, directory):
base = directory.replace("\\", "/")
for root, dirs, files in os.walk(directory):
for file in files:
if file.endswith(".py"):
full_path = os.path.join(root, file).replace("\\", "/")
relative = full_path[len(base):].lstrip("/")
module = f"Cogs.{relative[:-3].replace('/', '.')}"
await self.load_extension(module)
print(f"Loaded cog: {module}")
async def on_ready(self):
print(
'------------------------------------------------------------------------\n'
f'Logged in as {self.user} (ID: {self.user.id})\n'
'------------------------------------------------------------------------'
)
bot = MyClient()
bot.run(botConfig.BOT_TOKEN)