-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
70 lines (60 loc) · 1.91 KB
/
main.py
File metadata and controls
70 lines (60 loc) · 1.91 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
69
70
"""
Discord Moderation Bot with Cogs
--------------------------------
This bot includes essential moderation commands organized in cogs.
"""
import os
import discord
from discord.ext import commands
import asyncio
import datetime
import json
from typing import Optional, Union
# Bot configuration
intents = discord.Intents.default()
intents.members = True
intents.message_content = True
bot = commands.Bot(command_prefix='!', intents=intents)
# Load configuration from config.json or create default
try:
with open('config.json', 'r') as f:
config = json.load(f)
except FileNotFoundError:
config = {
"token": "YOUR_BOT_TOKEN_HERE",
"log_channel": None,
"mute_role": None
}
with open('config.json', 'w') as f:
json.dump(config, f, indent=4)
# Main bot file
@bot.event
async def on_ready():
print(f'Logged in as {bot.user.name} ({bot.user.id})')
print(f'Bot is ready to moderate!')
# Load all cogs
for cog_file in os.listdir("cogs"):
if cog_file.endswith(".py"):
try:
await bot.load_extension(f"cogs.{cog_file[:-3]}")
print(f"Loaded extension: {cog_file[:-3]}")
except Exception as e:
print(f"Failed to load extension {cog_file[:-3]}: {e}")
# Set custom status
await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name="for rule breakers"))
@bot.command()
@commands.is_owner()
async def reload(ctx, cog):
"""Reload a cog (owner only)"""
try:
await bot.reload_extension(f"cogs.{cog}")
await ctx.reply(f"Reloaded {cog} successfully!")
except Exception as e:
await ctx.reply(f"Error reloading {cog}: {e}")
# Run the bot
if __name__ == "__main__":
# Create cogs directory if it doesn't exist
if not os.path.exists("cogs"):
os.makedirs("cogs")
# Start the bot
bot.run(config["token"])