A script that lets you control your Minecraft server using a Discord bot.
- Allow specific users to start the server
- Allow specific users to execute console commands
- Allow users to send messages to Minecraft from Discord and vise versa
- Download the script from the repository.
- Create two text channels: one for your game chat, and one for console output.
- Create a voice channel to show whether the server is online or shut down.
- 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 box, check Read Messages/View Channels and Send Messages.
- Copy the URL and open it. Invite the bot to your server. Go back to the General Information tab and find the Application ID. We'll need it later.
- Open the script using a text editor.
- Find
var MC_SERVER_START_SCRIPT. ReplaceC:/Users/username/start.batwith the full path to your start.bat, start.sh, or start.command file.- If you don't have a start command file, look up a tutorial on how to create a start script for your server.
- Find
var gamechat. Replace<ID_HERE_WITHOUT_BRACKETS>with the ID of your game chat channel.- To find the ID of an object in Discord, turn on Developer Mode in Discord settings and right click the object you want the ID of. Click Copy ID.
- Find
var serverstatus. Replace<ID_HERE_WITHOUT_BRACKETS>with the ID of your server status voice channel. - Find
var consolemaster. Replace<NAME_HERE_WITHOUT_BRACKETS>with the name of the role you want to allow access to console commands. - Go to the bottom of the script. Replace
<BOT_TOKEN_WITHOUT_BRACKETS>with the application ID you found earlier.
- If you already have Node.js installed, skip to step six.
- Go to https://nodejs.org/en/ and either download the recommended release or (if using Linux) install using your package manager using the directions on this page: https://nodejs.org/en/download/package-manager/
- Follow the installation steps.
- Open the terminal or command prompt and execute the following commands:
node install tree-kill
node install child_process
node install discord.js
You're done with the installation!
Let's go through the process of using the bot.
- Using the terminal or command prompt, run
node path/to/console-bot.js, replacing path/to/console-bot.js with the path to the script. - If you see
Bot Online! Woohoo!the bot has successfully connected. - In your console channel, use
startto start the server. Make sure you have the console master role. - Once the server has started, you can execute Minecraft commands using - as a prefix rather than /.
- In your game chat channel, messages from Minecraft should be seen and messages sent in that channel should be seen in Minecraft.
- The server status should automatically change when the server is online.
- You can use
killto force-stop the server. This should not be used as a replacement for -stop.
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. As long as your bot ID doesn't get out, you should be fine.
- The bot cannot detect a server that is already running. This is impossible to do with the current implementation.
- The bot cannot detect when the server has been -stopped. You must kill it (although this is safe to do once it has shut down).
- Messages with line breaks do not work correctly when sending messages from Discord to Minecraft. I intend to fix this.