55 lines
1.5 KiB
Python

import logging
import asyncio
import os
import secret_handler
import discord
from discord import app_commands
from discord import Interaction
from discord.ext import commands
import addons
from client import Client
bot_info = {'version': '1.1.0', 'date': '20.02.2024'}
logger = logging.getLogger('discord')
logger.setLevel(logging.DEBUG)
logging.getLogger('discord.http').setLevel(logging.INFO)
handler = logging.FileHandler(filename='data/log/discord.log', encoding='utf-8', mode='a')
# dt_fmt = '%Y-%m-%d %H:%M:%S'
# formatter = logging.Formatter('[{asctime}] [{levelname:<8}] {name}: {message}', dt_fmt, style='{')
formatter = logging.Formatter('%(asctime)s|%(levelname)s|%(name)s|:%(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
bot = Client(intents=discord.Intents.all(), command_prefix="!", log=logger, bot_info=bot_info)
async def load_cogs():
for filename in os.listdir("./cogs"):
if filename.endswith("py") and filename != "__init__.py":
await bot.load_extension(f"cogs.{filename[:-3]}")
@bot.event
async def on_ready():
logger.info(f"Logged in as: {bot.user.name} with ID {bot.user.id}")
await load_cogs()
await asyncio.sleep(1)
synced = await bot.tree.sync()
logger.info(f"Synced {len(synced)} command(s)")
@bot.event
async def on_app_command_error(interaction: Interaction, error):
if isinstance(error, app_commands.MissingPermissions):
await interaction.response.send_message(content="Du hast keine Adminrechte", ephemeral=True)
else:
raise error
bot.run(secret_handler.get_bot_token())