I want to make a discord bot in pyhton to start a minecraft server so a bat file but it cant find the user_jvm_args.txt file even when i say the code where it is. I am not good a coding I did most parts with Chatgpt if there are weird lines Yes I imported the token. here is the code:
import discord
from discord.ext import commands
import subprocess
import os
import asyncio
client = commands.Bot(command_prefix="!", intents=discord.Intents.all())
running_process = None
BOT_TOKEN = 'Token' # Replace 'YOUR_DISCORD_BOT_TOKEN' with your actual Discord bot token
@client.event
async def on_ready():
print("The bot is now ready for use!")
@client.command()
async def start(ctx):
global running_process
if running_process and running_process.poll() is None:
await ctx.send("A process is already running.")
return
batch_file_path = r"C:/Users/tomwi/Desktop/Dommmamjaydenantom/run.bat" # Update this path
user_jvm_args_path = r"C:/Users/tomwi/Desktop/Dommmamjaydenantom/user_jvm_args.txt" # Update this path
try:
await execute_batch_file(ctx, batch_file_path, user_jvm_args_path)
except Exception as e:
await ctx.send(f"Failed to start batch file: {e}")
async def execute_batch_file(ctx, batch_file_path, user_jvm_args_path):
with open(user_jvm_args_path, 'r') as f:
user_jvm_args = f.read().strip()
command = f'java @{user_jvm_args} -Xmx10G -Xms9G "{batch_file_path}"'
running_process = await asyncio.create_subprocess_shell(command)
await ctx.send("Batch file started.")
@client.command()
async def stop(ctx):
global running_process
if running_process and running_process.poll() is None:
try:
running_process.terminate()
await ctx.send("Batch file stopped.")
except Exception as e:
await ctx.send(f"Failed to stop batch file: {e}")
else:
await ctx.send("No batch file is currently running.")
client.run(BOT_TOKEN)
I tried many things like putting the file in the directory of the bot origanlly the file wasn't metionend in the code but then I implementet it and it did nothing but like I said I don't know anything when it comes to programing