-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
54 lines (42 loc) · 1.59 KB
/
main.py
File metadata and controls
54 lines (42 loc) · 1.59 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
import discord
import os
from dotenv import load_dotenv
from discord.ext import commands
from discord import app_commands
from utility import *
import logging
from loguru import logger
import sys
intents = discord.Intents.default()
intents.message_content = True
intents.members = True
client = discord.Client(intents=intents)
tree = app_commands.CommandTree(client)
token = os.environ.get('TOKEN')
MY_GUILD = discord.Object(id=os.environ.get('MY_GUILD'))
bot = commands.Bot(command_prefix='./', description="KeaneBot", intents=intents, help_command=None)
class InterceptHandler(logging.Handler):
"""Intercept existing logging handlers with Loguru."""
def emit(self, record: logging.LogRecord) -> None:
"""Emit a log to loguru."""
try:
level = logger.level(record.levelname).name
except ValueError:
level = record.levelno
frame, depth = sys._getframe(6), 6
while frame and frame.f_code.co_filename == logging.__file__:
frame = frame.f_back
depth += 1
logger.opt(depth=depth, exception=record.exc_info).log(level, record.getMessage())
logging.basicConfig(handlers=[InterceptHandler()], level=logging.INFO, force=True)
@bot.event
async def on_ready():
"""Start the bot."""
bot.tree.copy_global_to(guild=MY_GUILD)
await bot.tree.sync(guild=MY_GUILD)
logger.info(f"Bot started. Logged in as {bot.user}")
@bot.tree.command()
async def ping(interaction: discord.Interaction) -> None:
"""Ping the bot."""
await interaction.response.send_message("Pong! :ping_pong:")
bot.run(token, log_handler=None)