-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.py
59 lines (46 loc) · 1.75 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
import logging
import os
from datetime import UTC, datetime
import discord
from aiohttp import ClientSession
from discord.ext import commands
from config import config
class Bot(commands.AutoShardedBot):
error_channel: discord.TextChannel
session: ClientSession
launch_time: int
colour = 0xFF7000
def __init__(self, *args, **kwargs):
super().__init__(
*args,
**kwargs,
command_prefix=commands.when_mentioned,
help_command=None,
intents=discord.Intents.default(),
case_insensitive=True,
allowed_mentions=discord.AllowedMentions(everyone=False),
allowed_installs=discord.app_commands.AppInstallationType(
guild=True, user=True
),
allowed_contexts=discord.app_commands.AppCommandContext(
guild=True, dm_channel=True, private_channel=True
),
)
async def setup_hook(self) -> None:
await self.load_extension("jishaku")
for cog in os.listdir("./cogs"):
if cog.endswith(".py"):
await self.load_extension(f"cogs.{cog[:-3]}")
self.error_channel = await self.fetch_channel(config["error_channel"])
self.session = ClientSession()
self.launch_time = round(datetime.now(UTC).timestamp())
async def on_ready(self) -> None:
print(f"Logged in as {self.user} (ID: {self.user.id})")
async def close(self) -> None:
if hasattr(self, "session"):
await self.session.close()
await super().close()
bot = Bot()
if __name__ == "__main__":
logging_level = logging.DEBUG if config.get("debug") else logging.WARNING
bot.run(config["token"], log_level=logging_level, root_logger=True)