Files
discord_bot/bot.py
2022-09-02 09:47:18 +03:00

70 lines
1.8 KiB
Python
Executable File

#!/usr/bin/env python3
import asyncio
import os
import disnake
from disnake import OptionChoice, OptionType, Option
from disnake.ext import commands
from __init__ import version_info
from lib import work_with_cogs
from lib import preload_checks, determine_prefix
from lib import logger
preload_checks()
intents = disnake.Intents(messages=True,
guilds=True,
message_content=True,
voice_states=True,
members=True,
presences=True
)
bot = commands.Bot(command_prefix=determine_prefix,
intents=intents,
reload=True
)
asyncio.run(work_with_cogs('load', bot))
@bot.event
async def on_ready():
logger.info(f'Bot started')
logger.info('We have logged in as {0.user}'.format(bot))
logger.info('Version of bot is - v{0.major}.{0.minor}.{0.micro}-{0.releaselevel}'.format(version_info))
@bot.slash_command(
name="cog",
description="Work with cogs",
options=[
Option(
"what_do",
description="Specify what do with cogs",
type=OptionType.string,
required=True,
choices=[
OptionChoice("load", "load"),
OptionChoice("unload", "unload"),
OptionChoice("reload", "reload")
]
)
]
)
@commands.is_owner()
async def slash_cogs(inter, what_do):
await work_with_cogs(what_do, bot)
await inter.response.send_message(f'Cogs are {what_do}ed', ephemeral=True)
@slash_cogs.error
async def cogs_error(inter, what_do):
await inter.response.send_message(f'{what_do}', ephemeral=True)
logger.error(f'User {inter.author} tries to use cogs func')
bot.run(os.getenv('TOKEN'))