Files
cogs
bot.py
config.json
requirements.txt
Code
5 389
bot.py
import discord
from discord.ext import commands
import os
import json
import logging
from dotenv import load_dotenv
load_dotenv()
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s"
)
log = logging.getLogger("bot")
CONFIG_PATH = "config.json"
def load_config():
if not os.path.exists(CONFIG_PATH):
return {}
with open(CONFIG_PATH, "r") as f:
return json.load(f)
def save_config(data: dict):
with open(CONFIG_PATH, "w") as f:
json.dump(data, f, indent=2)
intents = discord.Intents.default()
intents.guilds = True
bot = commands.Bot(command_prefix="!", intents=intents)
bot.config_path = CONFIG_PATH
bot.load_config = load_config
bot.save_config = save_config
PLACE_ID = 5507622398
@bot.event
async def on_ready():
log.info(f"Logged in as {bot.user} (ID: {bot.user.id})")
try:
synced = await bot.tree.sync()
log.info(f"Synced {len(synced)} slash commands.")
except Exception as e:
log.error(f"Failed to sync commands: {e}")
async def main():
async with bot:
await bot.load_extension("cogs.monitor")
await bot.load_extension("cogs.setup")
await bot.start(os.getenv("DISCORD_TOKEN"))
if __name__ == "__main__":
import asyncio
asyncio.run(main())