-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
74 lines (62 loc) · 2.25 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
65
66
67
68
69
70
71
72
73
74
import os
import discord
from discord.ext import commands
from utils.config import Config
from utils.logger import Logger
from utils.errors import (
InvalidVoiceChannel,
TrackNotFound,
AlreadyConnected,
NotInVoice,
NoPermissions,
NotConnected,
PlaylistNotFound,
PlaylistError,
)
# Load configuration settings
config = Config()
# Create a logger instance
logger = Logger(__name__)
# Define the bot instance
intents = discord.Intents.default()
intents.members = True
intents.presences = True
intents.message_content = True
bot = commands.Bot(command_prefix=config.prefix, intents=intents)
# Load cogs
for filename in os.listdir("./cogs"):
if filename.endswith(".py"):
bot.load_extension(f"cogs.{filename[:-3]}")
@bot.event
async def on_ready():
logger.info(f"Bot is ready! Logged in as {bot.user}")
@bot.event
async def on_command_error(ctx, error):
if isinstance(error, commands.CommandNotFound):
await ctx.send("Invalid command. Use `!help` to see available commands.")
elif isinstance(error, InvalidVoiceChannel):
await ctx.send(
"Please join a valid voice channel first. You may need to reconnect to the voice channel."
)
elif isinstance(error, TrackNotFound):
await ctx.send(f"Track not found. Please try a different search query.")
elif isinstance(error, AlreadyConnected):
await ctx.send("I am already connected to a voice channel.")
elif isinstance(error, NotInVoice):
await ctx.send("You need to be in a voice channel to use this command.")
elif isinstance(error, NoPermissions):
await ctx.send("You do not have the permissions to use this command.")
elif isinstance(error, NotConnected):
await ctx.send("I am not connected to a voice channel.")
elif isinstance(error, PlaylistNotFound):
await ctx.send("Playlist not found. Please check the playlist name.")
elif isinstance(error, PlaylistError):
await ctx.send("An error occurred while managing the playlist.")
else:
logger.error(f"Unhandled error: {error}")
await ctx.send(
"An error occurred. Please try again later or contact the bot administrator."
)
# Run the bot
if __name__ == "__main__":
bot.run(config.token)