import json import logging import sys import threading import discord import lib from os import path from discord.ext import commands from dislash import InteractionClient, Option, OptionType, OptionChoice bot_owner = 386629192743256065 lib.Commands.chech_json() intents = discord.Intents.default() intents.members = True bot = commands.Bot(command_prefix=lib.Commands.determine_prefix, guild_subscriptions=True, intents=intents) inter_client = InteractionClient(bot, sync_commands=True) threading.current_thread().name = "main" logging.basicConfig(stream=sys.stdout, filemode='w', level='INFO', format='%(asctime)s - %(levelname)s - %(threadName)s - %(message)s') for filename in lib.CogsPrepare.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)) @inter_client.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(ctx, what_do): if ctx.author.id == bot_owner: await lib.CogsPrepare.work_with_cogs(what_do, bot) await ctx.reply(f'Cogs are {what_do}ed', ephemeral=True) else: await ctx.reply('You`re not bot owner', ephemeral=True) bot.run('OTQ3OTUzOTAxNzgzNjIxNjYy.GTXbMv.KrztaTO7-ivsPEAVjsyikSQ-GP-ANwULmDraig')