Files
discord_bot/test.py
2022-08-23 20:44:19 +03:00

78 lines
2.3 KiB
Python

import logging
import sys
from os import path
import disnake
from disnake import OptionChoice, OptionType, Option
from disnake.ext import commands
from lib.CogsPrepare import cog_list, work_with_cogs
from lib.Comands import determine_prefix
if not path.isfile('prefix.json'):
with open('prefix.json', 'w+', encoding='utf-8') as f:
f.write("")
intents = disnake.Intents(messages=True,
guilds=True,
message_content=True,
voice_states=True,
members=True)
bot = commands.Bot(command_prefix=determine_prefix,
intents=intents,
reload=True,
test_guilds=[929446191270330410, 987120286933602354])
logging.basicConfig(stream=sys.stdout, filemode='w', level='INFO',
format='%(asctime)s - %(levelname)s - %(module)s - %(message)s')
for filename in cog_list():
try:
bot.load_extension(f'cogs.{filename}')
logging.info(f'Loaded cog {filename}')
except commands.ExtensionNotFound:
logging.error(f"Error: {filename} couldn't be found to load.")
except commands.ExtensionFailed as error:
logging.error(f'Error: {filename} failed to load properly.', error)
except commands.ExtensionError:
logging.error(f'Error: unknown error with {filename}')
@bot.event
async def on_ready():
logging.info(f'Bot started')
logging.info('We have logged in as {0.user}'.format(bot))
@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")
]
)
]
)
async def slash_cogs(inter, what_do):
if inter.author.id == bot.owner_id:
await work_with_cogs(what_do, bot)
await inter.response.send_message(f'Cogs are {what_do}ed', ephemeral=True)
else:
await inter.response.send_message('You`re not bot owner', ephemeral=True)
bot.run('OTQ3OTUzOTAxNzgzNjIxNjYy.GTXbMv.KrztaTO7-ivsPEAVjsyikSQ-GP-ANwULmDraig')