-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
68 lines (57 loc) · 2.09 KB
/
bot.py
File metadata and controls
68 lines (57 loc) · 2.09 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
64
65
66
67
68
import os
import asyncio
import discord
from discord.ext import commands
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
# Define intents
intents = discord.Intents.default()
intents.message_content = True
intents.members = True
# Ensure data directory exists
os.makedirs('data', exist_ok=True)
# Initialize bot with prefix
bot = commands.Bot(command_prefix='?', intents=intents)
@bot.event
async def on_ready():
print(f'{bot.user} has connected to Discord!')
# Check Database Connection
import db
conn = db.get_connection()
if conn:
print("✅ Database connected successfully!")
conn.close()
else:
print("❌ Failed to connect to Database!")
async def main():
async with bot:
# Load extensions from commands
if os.path.exists('./commands'):
for filename in os.listdir('./commands'):
if filename.endswith('.py'):
await bot.load_extension(f'commands.{filename[:-3]}')
print(f'Loaded extension: commands.{filename}')
# Load extensions from admincommands
if os.path.exists('./admincommands'):
for filename in os.listdir('./admincommands'):
if filename.endswith('.py'):
await bot.load_extension(f'admincommands.{filename[:-3]}')
print(f'Loaded extension: admincommands.{filename}')
# Load extensions from functions
if os.path.exists('./functions'):
for filename in os.listdir('./functions'):
if filename.endswith('.py'):
await bot.load_extension(f'functions.{filename[:-3]}')
print(f'Loaded extension: functions.{filename}')
await bot.start(TOKEN)
if __name__ == "__main__":
if not TOKEN or TOKEN == "your_token_here":
print("Error: DISCORD_TOKEN not found in .env or is still default.")
else:
try:
asyncio.run(main())
except KeyboardInterrupt:
# Handle Ctrl+C gracefully
pass