-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
74 lines (57 loc) · 2.23 KB
/
bot.py
File metadata and controls
74 lines (57 loc) · 2.23 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
71
72
73
74
"""This is where the bot's main code is in."""
# Third Party Imports
import os
import logging
from urllib.parse import quote_plus
from dotenv import load_dotenv
from motor.motor_asyncio import AsyncIOMotorDatabase
# Discord.py
import discord
from discord.ext import commands
# First Party Imports
from utils.logging import logging_setup
from utils.cogs import load_cogs
from utils.db import init_db
class Bot(commands.Bot):
"""An extended version of the discord.py bot class"""
def __init__(self, prefix, *, intents):
# pylint: disable=C0103
self.db: AsyncIOMotorDatabase = init_db(os.getenv('MONGO_HOSTNAME'), int(os.getenv('MONGO_PORT')), os.getenv('MONGO_DB'), quote_plus(os.getenv('MONGO_USERNAME') if os.getenv('MONGO_USERNAME') else ''), quote_plus(os.getenv('MONGO_PASSWORD') if os.getenv('MONGO_PASSWORD') else ''))
self.root = logging_setup(int(os.getenv('LOG_LEVEL')))
super().__init__(prefix, intents=intents)
def main() -> None:
"""The main function"""
load_dotenv()
token = os.getenv('DISCORD_TOKEN')
intents = discord.Intents.default()
intents.message_content = True
bot = Bot('%', intents=intents)
load_cogs(bot)
@bot.event
async def on_ready():
"""Prepares the bot when it is ready"""
bot.root.log(logging.INFO,
f'I am logged in as {bot.user.name}#{bot.user.discriminator}')
@commands.is_owner()
@bot.command()
async def sync(ctx: commands.Context):
"""Synchronizes app commands with debug guild
Args:
ctx (commands.Context): The context of the interaction
"""
guild = bot.get_guild(1091153826112872508)
bot.tree.copy_global_to(guild=guild)
synced = await bot.tree.sync(guild=guild)
await ctx.send(f'Synced {len(synced)} commands to {guild.name}!')
@commands.is_owner()
@bot.command()
async def syncglobal(ctx: commands.Context):
"""Synchronizes app commands globally
Args:
ctx (commands.Context): The context of the interaction
"""
synced = await bot.tree.sync()
await ctx.send(f'Synced {len(synced)} commands globally!')
bot.run(token, log_handler=None)
if __name__ == '__main__':
main()