-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
60 lines (52 loc) · 1.6 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
from discord import Intents, VoiceClient
from discord.ext.commands import Bot
from dotenv import load_dotenv
import logging
from os import getenv
from pathlib import Path
logger = logging.basicConfig(
format='%(asctime)s : %(name)s - %(levelname)s - %(message)s',
level=logging.WARNING
)
# No Discord voice support required, turn warning off
VoiceClient.warn_nacl = False
load_dotenv() # Loading token
TOKEN = getenv('DISCORD_TOKEN')
if not TOKEN:
print('RIP, no TOKEN.')
exit()
class TSDBot(Bot):
"""
The Space Devs Discord bot.
"""
def __init__(self) -> None:
super().__init__(
command_prefix=(),
help_command=None,
intents=Intents.default()
)
# Extensions to load
self.initial_extensions = [
f"{'.'.join(file.parent.parts)}.{file.stem}"
for file in Path('extensions').glob('**/*.py')
if file.suffix == '.py'
]
async def setup_hook(self) -> None:
"""
Setting up the bot by loading extensions
and syncing application commands.
"""
# Load extensions during setup
for extension in self.initial_extensions :
await self.load_extension(extension)
print(f'Loaded {extension}')
# Create application commands if needed
if False:
response = await self.tree.sync()
print(response)
bot = TSDBot()
@bot.event # On startup
async def on_ready():
# Print amount of servers joined
print(f'{bot.user} Connected to {len(bot.guilds)} servers.')
bot.run(TOKEN, log_handler=logger)