-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
64 lines (48 loc) · 1.65 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
import asyncio
import os
import signal
import sys
import disnake
from src import constants, log
from src.bot import Bot
from src.constants import Client
logger = log.get_logger(__name__)
_intents = disnake.Intents.all()
async def main() -> None:
"""Start bot."""
bot = Bot(
intents=_intents,
owner_ids=set(constants.Client.owner_ids),
reload=constants.Client.reload,
)
bot.i18n.load("src/lang/") # type: ignore[reportUnknownMemberType]
try:
bot.load_extensions("src/exts")
except Exception:
await bot.close()
raise
logger.info("Bot is starting.")
try:
if os.name != "nt":
# start process for linux host
loop = asyncio.get_event_loop()
future = asyncio.ensure_future(bot.start(Client.token or ""), loop=loop)
loop.add_signal_handler(signal.SIGINT, lambda: future.cancel())
loop.add_signal_handler(signal.SIGTERM, lambda: future.cancel())
await future
else:
await bot.start(Client.token or "")
except (asyncio.CancelledError, KeyboardInterrupt):
logger.warning("Kill command received. Bot is closed.")
if not bot.is_closed():
await bot.close()
except disnake.errors.PrivilegedIntentsRequired:
msg = f"""Missing Privileged Intents.
Fix this by adding the required privileged intents for your bot inside of:
| https://discord.com/developers/applications/{bot.user.id}/bot
"""
logger.critical(msg)
if not bot.is_closed():
await bot.close()
if __name__ == "__main__":
sys.exit(asyncio.run(main()))