Files
discord_bot/bot.py
2022-09-07 21:36:09 +03:00

86 lines
2.3 KiB
Python
Executable File

#!/usr/bin/env python3
import asyncio
import os
from typing import List
import disnake
from disnake import OptionChoice, OptionType, Option
from disnake.ext import commands
from __init__ import version_info as ver
from lib import work_with_cogs, cog_list
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, cog_list()))
@bot.event
async def on_ready():
logger.info(f'Bot started')
logger.info('We have logged in as {0.user}'.format(bot))
logger.info(f'Version of bot is - v{ver.major}.{ver.minor}.{ver.micro}-{ver.releaselevel}')
@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")
]
),
Option(
'cog',
description="specify cog",
type=OptionType.string
)
]
)
@commands.is_owner()
async def slash_cogs(inter, what_do, cog: str = cog_list()) -> None:
print(type(inter.guild.text_channels))
await work_with_cogs(what_do, bot, cog)
await inter.response.send_message(f'Cogs are {what_do}ed', ephemeral=True)
@slash_cogs.autocomplete('cog')
async def _cog_opt(inter: disnake.ApplicationCommandInteraction, current: str) -> List[OptionChoice]:
_list = cog_list()
return [
OptionChoice(name=choice, value=choice)
for choice in _list if current.lower() in choice.lower()
]
@slash_cogs.error
async def cogs_error(inter, what_do):
await inter.response.send_message(f'Error', ephemeral=True)
logger.error(f'User {inter.author} tries to use cogs func\n{what_do}\n')
bot.run(os.getenv('TOKEN'))