-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
58 lines (48 loc) · 1.86 KB
/
bot.py
File metadata and controls
58 lines (48 loc) · 1.86 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
import discord
from discord.ext import commands
import os
import json
import asyncio
def get_prefix(bot, message):
with open("prefixes.json", "r") as f:
prefixes = json.load(f)
return prefixes.get(str(message.guild.id), getattr(bot, "default_prefix", "!"))
def build_embed(title, description, color=discord.Color.green()):
return discord.Embed(title=title, description=description, color=color)
intents = discord.Intents.default()
intents.message_content = True
intents.members = True
intents.presences = True
bot = commands.Bot(command_prefix=get_prefix, intents=intents)
bot.default_prefix = "kf!"
@bot.event
async def on_ready():
print(f"Logged in as {bot.user} (ID: {bot.user.id})")
print("------")
@bot.event
async def on_command_error(ctx, error):
if isinstance(error, commands.CheckFailure):
await ctx.send(embed=build_embed("Access Denied", "❌ You don't have permission to use this command.", discord.Color.red()))
async def load_cogs():
for filename in os.listdir("./commands"):
if filename.endswith(".py") and filename != "__init__.py":
try:
await bot.load_extension(f"commands.{filename[:-3]}")
print(f"✅ Loaded: {filename}")
except Exception as e:
print(f"❌ Failed to load {filename}: {e}")
async def load_utility():
for filename in os.listdir("./util"):
if filename.endswith(".py") and filename not in ("__init__.py", "punishment_manager.py"):
try:
await bot.load_extension(f"util.{filename[:-3]}")
print(f"✅ Loaded: {filename}")
except Exception as e:
print(f"❌ Failed to load {filename}: {e}")
async def main():
async with bot:
await load_cogs()
await load_utility()
await bot.start("TOKEN")
# Start the bot
asyncio.run(main())