-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
75 lines (61 loc) · 1.96 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import logging
import os
from pathlib import Path
import discord
import dotenv
from discord.ext import commands
from pretty_help import PrettyHelp
from internal import constants
from internal.constants import ACC_PURPLE
logger = logging.getLogger()
logger.setLevel(logging.INFO)
consoleHandle = logging.StreamHandler()
consoleHandle.setLevel(logging.INFO)
consoleHandle.setFormatter(
logging.Formatter("%(name)-18s :: %(levelname)-8s :: %(message)s")
)
logger.addHandler(consoleHandle)
bot = commands.Bot(
command_prefix=commands.when_mentioned_or(";"),
description="A bot for CS/IT @ ACC Discord server.",
intents=discord.Intents.all(),
help_command=PrettyHelp(show_index=False, color=ACC_PURPLE),
case_insensitive=True,
)
async def load_all_extensions():
"""Load all *.py files in /cogs/ as Cogs."""
cogs = [x.stem for x in Path("cogs").glob("*.py")]
logger.info("")
logger.info("Loading extensions...")
for extension in cogs:
try:
bot.load_extension(f"cogs.{extension}")
logger.info(f"loaded {extension}")
except Exception as e:
error = f"{extension} - {type(e).__name__} : {e}"
logger.warning(error)
@bot.event
async def on_ready():
await load_all_extensions()
app_info = await bot.application_info()
logger.info(constants.ACC_ASCII_LOGO)
logger.info(
f"\n\nLogged in as: {bot.user.name}\n"
f"Using discord.py version: {discord.__version__}\n"
f"Owner: {app_info.owner}\n\n"
)
await bot.change_presence(
activity=discord.Activity(
type=discord.ActivityType.watching, name="hours of recorded lectures."
)
)
@bot.event
async def on_message(message):
"""Allow bot to ignore all other bots."""
if message.author.bot:
return
await bot.process_commands(message)
if __name__ == "__main__":
dotenv.load_dotenv(".env")
BOT_TOKEN = os.getenv("BOT_TOKEN")
bot.run(BOT_TOKEN)