Skip to content

flashvwolve/mc-console-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

mc-console-bot

A script that lets you control your Minecraft server using a Discord bot.

Features

  • 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

Installation

1. Download the file

  1. Download the script from the repository.

2. Prepare Discord

  1. Create two text channels: one for your game chat, and one for console output.
  2. Create a voice channel to show whether the server is online or shut down.
  3. Create a role that you want to allow access to console commands.

3. Create a bot

  1. Go to https://discord.com/developers/applications and create a new application. Give it any name, description, or icon.
  2. Go to the Bot tab and create a bot. Give it a name.
  3. Under the OAuth2 tab, go to URL Generator. Check the bot box. In the second box, check Read Messages/View Channels and Send Messages.
  4. 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.

4. Edit the script

  1. Open the script using a text editor.
  2. Find var MC_SERVER_START_SCRIPT. Replace C:/Users/username/start.bat with 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.
  3. 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.
  4. Find var serverstatus. Replace <ID_HERE_WITHOUT_BRACKETS> with the ID of your server status voice channel.
  5. Find var consolemaster. Replace <NAME_HERE_WITHOUT_BRACKETS> with the name of the role you want to allow access to console commands.
  6. Go to the bottom of the script. Replace <BOT_TOKEN_WITHOUT_BRACKETS> with the application ID you found earlier.

5. Download and Install Node.js

  1. If you already have Node.js installed, skip to step six.
  2. 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/
  3. Follow the installation steps.

6. Install required packages

  1. 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!

Operation

Let's go through the process of using the bot.

  1. 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.
  2. If you see Bot Online! Woohoo! the bot has successfully connected.
  3. In your console channel, use start to start the server. Make sure you have the console master role.
  4. Once the server has started, you can execute Minecraft commands using - as a prefix rather than /.
  5. In your game chat channel, messages from Minecraft should be seen and messages sent in that channel should be seen in Minecraft.
  6. The server status should automatically change when the server is online.
  7. You can use kill to force-stop the server. This should not be used as a replacement for -stop.

Security

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.

Known bugs

  • 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.

About

A script that lets you control your Minecraft server using a Discord bot.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published