-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathbot.py
67 lines (56 loc) · 2.17 KB
/
bot.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
import discord
import logging
from classes.discordbot import DiscordBot
from classes.utilities import load_config, clean_close, cogs_manager, set_logging, cogs_directory
from os import listdir
class Bot(DiscordBot):
def __init__(self, **kwargs) -> None:
# Set default values
kwargs.setdefault("activity", discord.Game(name = "Booting.."))
kwargs.setdefault("allowed_mentions", discord.AllowedMentions(everyone=False))
kwargs.setdefault("case_insensitive", True)
kwargs.setdefault("config", load_config())
kwargs.setdefault("intents", discord.Intents.all())
kwargs.setdefault("max_messages", 2500)
kwargs.setdefault("status", discord.Status.idle)
# Initialize the bot
super().__init__(**kwargs)
async def startup(self) -> None:
"""Sync application commands"""
await self.wait_until_ready()
# Sync application commands
synced = await self.tree.sync()
self.log(message = f"Application commands synced ({len(synced)})", name = "discord.startup")
async def setup_hook(self) -> None:
"""Initialize the bot, database, prefixes & cogs."""
# Initialize the DiscordBot setup hook
await super().setup_hook()
# Cogs loader
cogs = [f"cogs.{filename[:-3]}" for filename in listdir(cogs_directory) if filename.endswith(".py")]
await cogs_manager(self, "load", cogs)
self.log(message = f"Cogs loaded ({len(cogs)}): {', '.join(cogs)}", name = "discord.setup_hook")
# Sync application commands
self.loop.create_task(self.startup())
if __name__ == '__main__':
clean_close() # Avoid Windows EventLoopPolicy Error
bot = Bot(
intents = discord.Intents(
emojis = True,
guild_scheduled_events = True,
guilds = True,
invites = True,
members = True,
message_content = True,
messages = True,
presences = True,
reactions = True,
voice_states = True,
),
)
bot.logger, streamHandler = set_logging(file_level = logging.INFO, console_level = logging.INFO, filename = "discord.log")
bot.run(
bot.config["bot"]["token"],
reconnect = True,
log_handler = streamHandler,
log_level = logging.DEBUG, # Must be set to DEBUG, change the log_level of each handler in set_logging() method
)