-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
48 lines (36 loc) · 1.2 KB
/
main.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
import discord
from discord.ext import commands
import os
from pathlib import Path
from dotenv import load_dotenv
from pymongo import MongoClient
# Setting up global constants
load_dotenv()
BOT_TOKEN = os.getenv("BOT_TOKEN")
DEBUG_CHANNEL_ID = int(os.getenv("DEBUG_CHANNEL_ID"))
MONGO_DB_URL = os.getenv("MONGO_DB_URL")
mongo_cluster = MongoClient(MONGO_DB_URL)
# Loading guild prefixes
def fetch_guild_prefix(client: commands.Bot, message: discord.Message) -> str:
try:
return mongo_cluster["guildDatabase"]["guild_profiles"].find_one(
{"_id": message.guild.id}
)["command_prefix"]
except:
return ">>"
client = commands.Bot(
command_prefix=fetch_guild_prefix,
help_command=None,
intents=discord.Intents.all(),
)
@client.event
async def on_ready():
debug_channel = await client.fetch_channel(DEBUG_CHANNEL_ID)
await debug_channel.send(f"## Logged in as {client.user}")
print(f"Logged in as {client.user}")
# Loading cogs
for folder in os.listdir(Path("./cogs")):
for filename in os.listdir(Path(f"./cogs/{folder}")):
if filename.endswith("_cog.py"):
client.load_extension(f"cogs.{folder}.{filename[:-3]}")
client.run(BOT_TOKEN)