update command
This commit is contained in:
39
c/update.py
Normal file
39
c/update.py
Normal file
@@ -0,0 +1,39 @@
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
from discord.ext.commands import has_permissions, Context
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
|
||||
class Update(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.last_member = None
|
||||
|
||||
@commands.command()
|
||||
@commands.is_owner()
|
||||
async def update(self, context: Context, *args):
|
||||
"""
|
||||
Make pull from git repository and restart
|
||||
|
||||
"""
|
||||
res = await self.bot.ch(server_id=context.guild.id)
|
||||
channel = self.bot.get_channel(int(res))
|
||||
await channel.send('restarting...')
|
||||
try:
|
||||
subprocess.run(["git pull origin main"],capture_output=True)
|
||||
except:
|
||||
await channel.send('restart fail')
|
||||
return
|
||||
|
||||
python = sys.executable
|
||||
os.execv(python, [python] + sys.argv)
|
||||
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_ready(self):
|
||||
print('Update cog has been loaded')
|
||||
|
||||
|
||||
async def setup(bot):
|
||||
await bot.add_cog(Update(bot))
|
||||
Reference in New Issue
Block a user