I want to make a Discord bot to manage my Minecraft server for me and my friends, and I have a command to startup the server via subprocess, and to print the "server.jar" file's output into the python console. However, when attempting to send it to a specific channel within my Discord server, it fails to do so, but returns no error. If I stop the subprocess running the Minecraft server, the bot goes back online, but until then no command works, and it eventually goes offine. The command in question looks like the following:
@client.command()
async def start(ctx):
await client.change_presence(status=discord.Status.idle)
process = subprocess.Popen(["java", "-Xmx1024M", "-Xms1024M", "-jar", "server.jar", "nogui"], stdout=subprocess.PIPE, universal_newlines=True)
while True:
output = process.stdout.readline()
print(output.strip())
return_code = process.poll()
if return_code is not None:
for output in process.stdout.readlines():
print(output.strip())
tchannel = client.get_channel(967379407431925821)
await tchannel.send(output.strip())
if "Done" in output.strip():
ip = get('https://api.ipify.org')
await ctx.send("Done! Server Live on: "+ str(ip))
break
Any help is greatly appreciated, thanks!