From d48020c3b43c6084a13a406dbdc9a96ff70d93cd Mon Sep 17 00:00:00 2001 From: Marco Loewe Date: Tue, 14 Nov 2023 10:42:31 +0100 Subject: [PATCH] Added update command and permission check --- bot.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/bot.py b/bot.py index 4b426f4..ed8bbb0 100644 --- a/bot.py +++ b/bot.py @@ -3,8 +3,8 @@ import random import subprocess import json import discord -from discord.ext import commands from discord import app_commands +from discord.ext.commands import has_role, MissingRole with open('config.json', 'r') as f: @@ -34,9 +34,16 @@ async def cool(ctx): cool_factor = round(random.uniform(0, 100), 2) await ctx.response.send_message(f'{ctx.author} is {cool_factor}% cool!') -# @bot.command() -# async def update(ctx): -# subprocess.Popen('./update.sh') -# print(f'Updating, see you on the other side') +@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']) \ No newline at end of file