from genericpath import exists import random import subprocess import json import discord from discord import app_commands from discord.ext.commands import has_role, MissingRole with open('config.json', 'r') as f: data = json.load(f) if exists('config.local.json'): with open('config.local.json') as f: data = json.load(f) intents = discord.Intents.default() intents.message_content = True client = discord.Client(intents=intents) tree = app_commands.CommandTree(client) description = '''Bot to end all bots''' # bot = commands.Bot(command_prefix='?', description=description, intents=intents) @client.event async def on_ready(): await tree.sync(guild=discord.Object(id='745287426402156555')) print(f'Logged in as {client.user}') print('------') @tree.command(name = 'cool', description = 'Check how cool you are!', guild=discord.Object(id='745287426402156555')) async def cool(ctx): cool_factor = round(random.uniform(0, 100), 2) await ctx.response.send_message(f'{ctx.author} is {cool_factor}% cool!') @tree.command(name = 'update', description = 'Pulls the latest version from the repository', ) @has_role(745295653651087381) async def update(ctx): subprocess.Popen('./update.sh') print(f'Updating, see you on the other side') @update.error async def update_error(ctx: discord.Interaction, error): if isinstance(error, MissingRole): text = "Sorry {}, you do not have permissions to do that!".format(ctx.message.author) await ctx.response.send_message(text) client.run(data['token'])