1

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**")

1 Answer 1

2

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}")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.