Right now I have a command which allows you to apply changes to the local files on my hosting server. Is there a way to make the bot send await ctx.send(...) the output of the git reset command to Discord?
Normally the output looks like this:
HEAD is now at f8dd7fe Slash Commands/Pull Feature/JSON Changes!
This is my current command:
@client.command()
@commands.has_role('Bot Manager')
async def gitpull(ctx):
typebot = config['BotType']
if typebot == "BETA":
os.system("git fetch --all")
os.system("git reset --hard origin/TestingInstance")
await ctx.send("I have attempted to *pull* the most recent changes in **TestingInstance**")
elif typebot == "STABLE":
os.system("git fetch --all")
os.system("git reset --hard origin/master")
await ctx.send("I have attempted to *pull* the most recent changes in **Master**")
Sunderam Dubey
8,84812 gold badges26 silver badges43 bronze badges
asked Dec 31, 2020 at 16:25
SpaceTurtle0
1595 silver badges20 bronze badges
1 Answer 1
Use the subprocess module instead of os.system. That will allow you to capture the subprocess's output.
Something like:
@client.command()
@commands.has_role('Bot Manager')
async def gitpull(ctx):
typebot = config['BotType']
output = ''
if typebot == "BETA":
p = subprocess.run("git fetch --all", shell=True, text=True, capture_output=True, check=True)
output += p.stdout
p = subprocess.run("git reset --hard origin/TestingInstance", shell=True, text=True, capture_output=True, check=True)
output += p.stdout
await ctx.send(f"I have attempted to *pull* the most recent changes in **TestingInstance**\n{output}")
elif typebot == "STABLE":
p = subprocess.run("git fetch --all", shell=True, text=True, capture_output=True, check=True)
output += p.stdout
p = subprocess.run("git reset --hard origin/master", shell=True, text=True, capture_output=True, check=True)
output += p.stdout
await ctx.send(f"I have attempted to *pull* the most recent changes in **Master**\n{output}")
answered Dec 31, 2020 at 16:28
0x5453
13.8k2 gold badges36 silver badges70 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-py