A Python script that lets you start your Minecraft server using a Discord bot.
Download the script from the repository.
Create a role that you want to allow access to console commands.
- Go to https://discord.com/developers/applications and create a new application. Give it any name, description, or icon.
- Go to the Bot tab and create a bot. Give it a name.
- Under the OAuth2 tab, go to URL Generator. Check the bot box. In the second table, check the Read Messages/View Channels box.
- Scroll down and look for MESSAGE CONTENT INTENT under Privileged Gateway Intents. Enable the toggle.
- Copy the URL and open it. Invite the bot to your server. Go back to the Bot tab and find the Bot Token. Reset and copy it. We'll need it later.
- Open the script using a text editor.
- Find
TOKEN
. ReplaceYOUR_DISCORD_BOT_TOKEN
with the bot token you copied earlier. - Find
MINECRAFT_SERVER_PATH
. ReplaceC:/path/to/start.sh
with the full path to your start.bat, start.sh, or start.command file.- If you don't have a start command file, you can generate one at https://simplymc.art/flags/.
- Find
CONSOLE_MASTER
. ReplaceROLE_NAME
with the name of the role you want to allow to start the server.
- If you already have Python installed, skip to step six.
- Go to https://www.python.org/downloads/ and either download the latest source release or install
python3
using your package manager. - Follow the installation steps.
- Open the terminal or Windows Powershell and execute the following command.
python3 -m pip install -U discord.py
You're done with the installation!
Let's go through the process of using the bot.
- Using the terminal, run
python3 path/to/mc-console-bot.py
, replacing path/to/mc-console-bot.py with the path to the script. - If you see
Logged in as (bot username) - (bot client ID)
the bot has successfully connected. - In your Discord server, use
$startserver
to start the server. Make sure you have the console master role.
That's it!
Q: Is this safe? A: Yes. This script does not make any outside connections other than Discord.
Q: How do I know only my bot can access the script? A: Your bot ID links ONLY to your bot. Even if someone manages to get your bot token (which you should NEVER share with anyone), they will only be able to control the bot, not the server.
Make sure you have a valid bot token. Reread the setup steps to make sure you haven't missed anything.
A start script is a script that runs your Minecraft server JAR file. You can generate one at http://flags.sh/.
Make sure the path to your start script is formatted correctly. If the bot script and the start script are in the same folder, you can set MINECRAFT_SERVER_PATH
to ./start.sh
(or whatever your script is called.)
If you set a definite path make sure you prepend spaces with a backslash (\): /home/stonley890/Desktop/Minecraft\ Server/start.sh
. In this case, the Minecraft Server
folder needs a \ before the space.
If it still doesn't work, create an issue and I can help you.
Try relocating the mc-console-bot.py
script inside your server folder and setting the variable locally.
MINECRAFT_SERVER_PATH = './start.sh'
For more info, see #7.