Added update command and permission check

This commit is contained in:
Marco Loewe 2023-11-14 10:42:31 +01:00
parent 3a0c2ac8ab
commit d48020c3b4

17
bot.py
View File

@ -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'])