Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
63 lines (45 loc) · 2.05 KB
/
Copy pathmain.py
File metadata and controls
63 lines (45 loc) · 2.05 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
from __future__ import annotations
import discord
from discord.ext import commands
from dotenv import load_dotenv
import os
import logging
from discord import app_commands
from logger import log_error
load_dotenv()
TOKEN = os.getenv("VOICE_BOT_TOKEN")
if not TOKEN:
raise ValueError("VOICE_BOT_TOKEN not found in environment variables.") # Prevent silent failure if token is not found
os.makedirs("Logs", exist_ok=True)
log_path = os.path.join("Logs","VOICE_BOT.log")
voice_bot_log_handler = logging.FileHandler(filename=log_path,encoding="utf-8",mode='w')
# Bot configuration class
class MyBot(commands.Bot):
def __init__(self):
super().__init__(command_prefix="!", intents=discord.Intents.all(),help_command=None)
async def setup_hook(self):
await self.load_extension("cogs.voice_manager")
await self.load_extension("cogs.voice_interface")
await self.load_extension("cogs.voice_controls")
await self.load_extension("cogs.error_handling")
await self.load_extension("cogs.sync_command")
bot = MyBot()
@bot.tree.error
async def on_app_command_error(interaction: discord.Interaction, error: app_commands.AppCommandError): # Handle errors occurring in slash commands
error_log = False
if isinstance(error, app_commands.MissingPermissions):
msg = "❌ You don't have permission to use this command."
elif isinstance(error, app_commands.CommandOnCooldown):
retry_after = round(error.retry_after)
msg = f"⏳ Command on cooldown. Try again in **{retry_after}s**."
else:
msg = "⚠️ An unexpected error occurred."
error_log = True
if interaction.response.is_done():
await interaction.followup.send(msg, ephemeral=True)
else:
await interaction.response.send_message(msg, ephemeral=True)
if error_log: # Log unexpected errors for debugging
log_error(message="Unexpected Error - Location : on_app_command_error",exc_info=error)
if __name__ == "__main__":
bot.run(TOKEN,log_handler=voice_bot_log_handler,log_level=logging.DEBUG)