user8935928
user8935928

Reputation:

send whats popping up in the console?

I have a run command with my discord bot, it basically runs a bash command from the terminal. It works perfectly fine, but I want the discord bot to send what the command is saying in the console. for example if you type .run pwd, it should send a message saying the current directory. This is my code so far

@commands.check(owner)
async def run(ctx, *, arg):
  response = os.system(arg)
  ctx.author.send(response)  

Any help would be appreciated! thanks

Upvotes: 0

Views: 47

Answers (1)

Sujit
Sujit

Reputation: 1782

Are you looking for something like this?

@commands.is_owner()
@client.command()
async def run(ctx, *, arg):
    response = os.popen(arg).read()
    try:
        await ctx.author.send(response)
    except:
        await ctx.author.send(f'/bin/sh: 1: {arg}: not found')

Upvotes: 1

Related Questions