-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShellCommands.py
31 lines (31 loc) · 1.58 KB
/
ShellCommands.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
@client.command()
@commands.has_role('Bot Manager')
async def shell(ctx, * , command = None):
if command == None:
await missingArguments(ctx, "shell echo 'hello!'")
timestamp = datetime.now()
author = ctx.message.author
guild = ctx.message.guild
output = ""
try:
p = subprocess.run(command, shell=True, text=True, capture_output=True, check=True)
output += p.stdout
embed = discord.Embed(title = "Shell Process", description = f"Shell Process started by {author.mention}", color = 0x4c594b)
num_of_fields = len(output)//1014 + 1
for i in range(num_of_fields):
embed.add_field(name="Output" if i == 0 else "\u200b", value="```bash\n" + output[i*1014:i+1*1014] + "\n```")
embed.set_footer(text=guild.name + " | Date: " + str(timestamp.strftime(r"%x")))
await ctx.send(embed = embed)
except Exception as error:
tb = error.__traceback__
etype = type(error)
exception = traceback.format_exception(etype, error, tb, chain=True)
exception_msg = ""
for line in exception:
exception_msg += line
embed = discord.Embed(title = "Shell Process", description = f"Shell Process started by {author.mention}", color = 0x4c594b)
num_of_fields = len(output)//1014 + 1
for i in range(num_of_fields):
embed.add_field(name="Output" if i == 0 else "\u200b", value="```bash\n" + exception_msg[i*1014:i+1*1014] + "\n```")
embed.set_footer(text=guild.name + " | Date: " + str(timestamp.strftime(r"%x")))
await ctx.send(embed = embed)