This repository was archived by the owner on Jan 23, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
168 lines (134 loc) · 4.23 KB
/
main.py
File metadata and controls
168 lines (134 loc) · 4.23 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import asyncio
import logging
import os
from typing import Any
import discord
import pyfiglet
from disckit import CogEnum, UtilConfig
from disckit.cogs import dis_load_extension
from disckit.utils import MainEmbed
from dotenv import load_dotenv
from core import Bot
from core.config import (
COG_DIR,
ERROR_COLOR,
FOOTER_TEXT,
LOG_CHANNEL,
MAIN_COLOR,
SUCCESS_COLOR,
SYNC_GUILD_ID,
BotData,
)
from core.emojis import GREEN_CHECK, RED_CROSS
from core.utils import setup_logging
# Load environment variables from a `.env` file
load_dotenv()
# Set up logging for the application
setup_logging()
_logger: logging.Logger = logging.getLogger(__name__)
# Retrieve the Discord bot token from the environment variables
TOKEN = os.getenv("TOKEN")
# Set up Discord intents for the bot
intents = discord.Intents.all()
async def load_cogs(bot: Bot) -> None:
"""
Load all cogs from the specified cog directory.
Parameters
----------
bot : Bot
The bot instance to which the cogs will be loaded.
"""
for folder in os.listdir(COG_DIR):
for cog in os.listdir(COG_DIR + "/" + folder):
if cog.endswith(".py"):
cog_path = COG_DIR + "." + folder + "." + cog[:-3]
await bot.load_extension(cog_path)
async def custom_status(bot: Any, *args: Any) -> tuple[str, ...]:
"""
Generate a custom status for the bot.
Parameters
----------
bot : Any
The bot instance for which the status is being generated.
*args : Any
Additional arguments for the status function.
Returns
-------
tuple of str
A tuple containing status messages to be displayed.
"""
return (
f"version {BotData.VERSION}",
"Another Status Line Here",
"Use /help for commands",
)
async def main() -> None:
"""
The main entry point for the bot application.
This function initializes the bot, configures settings, loads cogs,
and starts the bot using the provided token.
Raises
------
ValueError
If the Discord bot token is not set in the environment variables.
"""
bot = Bot(intents=intents)
# Set up Discord's internal logging
discord.utils.setup_logging()
# Display a banner for the bot
print(pyfiglet.figlet_format("Disckit Example Bot")) # pyright: ignore[reportUnknownMemberType]
# Configure utility settings for the bot
UtilConfig.MAIN_COLOR = MAIN_COLOR
UtilConfig.SUCCESS_COLOR = SUCCESS_COLOR
UtilConfig.ERROR_COLOR = ERROR_COLOR
UtilConfig.SUCCESS_EMOJI = GREEN_CHECK
UtilConfig.ERROR_EMOJI = RED_CROSS
UtilConfig.FOOTER_IMAGE = BotData.AVATAR_URL
UtilConfig.FOOTER_TEXT = FOOTER_TEXT
UtilConfig.STATUS_FUNC = (custom_status, ())
UtilConfig.STATUS_TYPE = discord.ActivityType.listening
UtilConfig.STATUS_COOLDOWN = 600
UtilConfig.BUG_REPORT_CHANNEL = LOG_CHANNEL
UtilConfig.OWNER_LIST_URL = (
"https://images.disutils.com/bot_assets/assets/owners.txt"
)
UtilConfig.OWNER_ONLY_HELP_COGS = ("owner commands",)
UtilConfig.IGNORE_HELP_COGS = (
"owner commands",
"help cog",
"status handler",
"error handler",
"owner id handler",
"user count handler",
)
UtilConfig.OVERVIEW_HELP_EMBED = MainEmbed(
title="Bot's Overview",
description=(
"Welcome to the help overview of the bot.\n"
"Use the select menu from below to see the description of different command groups."
),
)
UtilConfig.HELP_OWNER_GUILD_ID = SYNC_GUILD_ID
# Load cogs and extensions
await load_cogs(bot=bot)
await dis_load_extension(
bot,
CogEnum.ERROR_HANDLER,
CogEnum.STATUS_HANDLER,
CogEnum.OWNER_IDS_HANDLER,
CogEnum.HELP_COG,
)
# Ensure TOKEN is not None
if not TOKEN:
raise ValueError(
"Discord bot token is not set in the environment variables."
)
# Start the bot using the token
await bot.start(TOKEN)
if __name__ == "__main__":
try:
asyncio.run(main())
except KeyboardInterrupt:
_logger.info("KeyboardInterrupt detected.")
except Exception as e:
_logger.exception(f"An error occurred: {e}")