-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
68 lines (57 loc) · 2.25 KB
/
main.py
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
from discord import app_commands
import discord
from discord.ext import commands
import os
import logging
import logging.handlers
from dotenv import load_dotenv
from discord.utils import get
from config import *
logger = logging.getLogger('discord')
load_dotenv()
intents = discord.Intents.all()
intents.message_content = True
class RankedBot(commands.Bot):
def __init__(self):
super().__init__(
command_prefix="!!!",
intents=discord.Intents.all(),
application_id=DISCORD_APPLICATION_ID)
self.ranked_cog = None
async def setup_hook(self):
await self.load_extension("cogs.ranked")
await self.load_extension("cogs.server")
await self.load_extension("cogs.general")
await self.load_extension("cogs.userManagement") # Load the new cog
await self.tree.sync(guild=discord.Object(id=GUILD_ID))
async def on_ready(self):
logger.info("The bot is alive!")
# Required to update all slash commands
await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching,
name=str("xRC Sim Ranked Queue")))
if self.ranked_cog:
await self.ranked_cog.startup()
logger.info("Bot startup complete")
def set_ranked_cog_reference(self, cog):
self.ranked_cog = cog
bot = RankedBot()
@app_commands.command()
async def ping(interaction: discord.Interaction):
await interaction.response.send_message('Pong! {0} :ping_pong: '.format(round(bot.latency * 1000, 4)),
ephemeral=False)
file_log_handler = logging.handlers.RotatingFileHandler(
filename='bot.log',
encoding='utf-8',
maxBytes=32 * 1024 * 1024, # 32 MiB
backupCount=5, # Rotate through 5 files
)
file_log_handler.setFormatter(logging.Formatter(
'%(asctime)s : %(levelname)s : %(name)s : %(message)s'))
logger.setLevel(logging.INFO)
logger.addHandler(file_log_handler)
stdout_log_handler = logging.StreamHandler()
stdout_log_handler.setFormatter(logging.Formatter(
'%(asctime)s : %(levelname)s : %(name)s : %(message)s'))
logger.setLevel(logging.INFO)
logger.addHandler(stdout_log_handler)
bot.run(DISCORD_BOT_TOKEN, log_handler=None)