-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
54 lines (46 loc) · 1.63 KB
/
app.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
# path: app.py
import os
import asyncio
import discord
from discord.ext import commands
from dotenv import load_dotenv
from bot_components.bot import Nanéu
from utils.errors import DiscordTokenErrors
# Load the .env file
load_dotenv()
def get_prefix(bot, message):
prefix = f'<@!{bot.user.id}> !'
return commands.when_mentioned_or(prefix)(bot, message)
async def load():
"""
Loads all the Python files in the 'cog' directory as extensions for the bot.
This function iterates over all the files in the 'cog' directory and loads each file
as an extension for the bot if it is a Python file (ends with '.py'). It prints a message
indicating whether each extension was successfully loaded or not.
"""
cog_dir = './cog'
for filename in os.listdir(cog_dir):
file_path = os.path.join(cog_dir, filename)
if os.path.isfile(file_path) and filename.endswith('.py'):
await bot.load_extension(f'cog.{filename[:-3]}')
if bot.load_extension:
print(f'Loaded {filename[:-3]} cog')
else:
print(f'Failed to load {filename[:-3]} cog')
intents = discord.Intents.default()
intents.messages = True
intents.message_content = True
bot = Nanéu(command_prefix=get_prefix,intents=intents)
async def main():
await load()
discord_token = os.getenv('DISCORD_TOKEN')
if discord_token is None:
DiscordTokenErrors.token_not_set_error()
return
else:
try:
await bot.start(discord_token)
except discord.LoginFailure:
DiscordTokenErrors.invalid_token_error()
return
asyncio.run(main())