File size: 2,399 Bytes
7cc32a6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f3747b5
7cc32a6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import os
import pathlib
import discord
from discord.ext import commands
import json
import asyncio
import traceback
from keep_alive import keep_alive

try:
    from dotenv import load_dotenv
    load_dotenv()
except Exception:
    pass


with open('config.json') as f:
    config = json.load(f)

TOKEN = os.getenv("DISCORD_TOKEN")
PREFIX = config.get("prefix", "!")

intents = discord.Intents.all()
intents.message_content = True 
bot = commands.Bot(
    command_prefix=PREFIX,
    intents=intents,
    case_insensitive=True,
    strip_after_prefix = True,
)


@bot.event
async def on_ready():
    print(f"Logged in as {bot.user} (ID: {bot.user.id})")
    try:
        synced = await bot.tree.sync()
        print(f"Synced {len(synced)} slash command(s)")
    except Exception as e:
        print(f"Failed to sync commands: {e}")


@bot.event
async def on_command_error(ctx: commands.Context, error: commands.CommandError):
    error = getattr(error, 'original', error)
    
    error_msg = ''.join(traceback.format_exception(type(error), error, error.__traceback__))
    
    if len(error_msg) > 1000:
        error_msg = error_msg[-1000:]
        error_msg = "..." + error_msg
    
    embed = discord.Embed(
        title="❌ Error Log",
        description=f"An error occurred while executing the command.",
        color=0xff0000
    )
    
    embed.add_field(
        name="Error Details",
        value=f"```py\n{error_msg}\n```",
        inline=False
    )
    
    embed.set_footer(text=f"Command: {ctx.command.name if ctx.command else 'Unknown'}")
    
    try:
        await ctx.send(embed=embed)
    except:
        await ctx.send(f"```py\n{error_msg}\n```")


async def load_cogs():
    cogs_dir = pathlib.Path(__file__).parent / "cogs"
    for file in cogs_dir.glob("*.py"):
        if file.stem.startswith("_") or file.stem == "functions":
            continue
        ext = f"cogs.{file.stem}"
        try:
            await bot.load_extension(ext)
            print(f"Loaded extension: {ext}")
        except Exception as e:
            print(f"Failed to load {ext}: {e}")


async def main():
    keep_alive()
    try:
        await bot.load_extension('jishaku')
        print("Loaded extension: jishaku")
    except Exception as e:
        print(f"Failed to load jishaku: {e}")
    await load_cogs()
    await bot.start(TOKEN)

if __name__ == "__main__":
    asyncio.run(main())