This is a NodeJS Minecraft Bot that let you manage or do in game operation via Discord. It's based off the work of the orginal author Amal Bansode Discord-Minecraft-Bot and uses the MineStat, the bot checks the status of user-specified Minecraft servers, teleport users to a specified coordinates, list the names of players in game, broadcast messages and a lot more to come.
This requires Node.js to be installed on your system, along with primary dependencies discord.js and minestat.js.
- Install Node.js and npm on your system. (You can use nvm or the Node.js binary.)
- Install mcrcon
- Clone this repository and place it in a folder. (Use
git clone https://github.com/cedroid09/homer-mc-discord
) - In terminal, navigate to this folder.
$ cd location/of/your/homer-mc-discord
- Install the latest
discord.js
using npm.$ npm i -S discord.js # You can remove the -S because npm now automatically saves it to package.json
- Create a Discord Application for the purpose of this bot. Setup a Discord account if you do not have one yet.
- Give the application/bot a name and description.
- Navigate to the ‘Bot’ section. Reveal your bot’s token, and copy it.
- Open
config.json
, which is contained in the same folder asbot.js
. - Paste your token within the double quotes corresponding to the "authtoken" key, and save.
- Now, with Terminal open in the same directory as before, run
$ node bot.js
- The output should say the following. If so, you have setup the bot correctly.
Logged in as <your bot’s discord tag>! Ready...
- Exit the application using a keyboard escape (typically
control/command + C
).
- On the Dicord Chat Client, click the '+' icon on the left side and create a new server for testing the bot. Skip this step if you manage a pre-existing server you want the bot to be added to.
- On the Discord Develper Portal for your bot, navigate to the section titled ‘OAuth2’. Scroll down to view the OAuth2 URL Generator.
- Check the following boxes:
- In Scopes, bot
- In Bot Permissions, Send Messages and Read Message History
- A URL must have been generated above. Follow this URL in a new browser tab.
- Specify the server you would like to add the bot to (this could be the one you created in step 1, or a pre-existing server).
- Verify the permissions stated, and click ‘Authorize’.
- The bot should now be a member of your specified server.
- Start the bot in Terminal again
$ node bot.js
- In the Discord chat window for this server, enter ‘!ip’ and check for output in your Discord chat.
The number of players on the server is displayed as the bot’s activity in the ‘Users‘ list on the right side.
The IP details of servers can be displayed in Discord chat by typing !ip
into Discord chat. The bot will reply to the user invoking the command.
The list of users in-game can be obtained by typing the keyword !playing
into any Discord chat. A list of users and server capacity will be printed.
Quick way to check if the server ready to accept connections.
Quickly sent out alert or message using the bot to all players in game.
The bot can be used to allow users on a vanilla server to teleport without any OP level permissions.
- Stop the bot if it is running. Open
config.json
in a text-editing program. - Change the parameters listed as follows:
{ "discord": { "authtoken": "<your_discord_authtoken_here" }, "mcrcon": { "path": "path/to/mcrcon/binary", "host": "host_ip", #ip for mcrcon to connect to the server "password": "mcrcon_password" #defined in server.properties }, "minecraft": { "host": "public.minecraft.server.dns", "hostname": "server_name", "port": "25565" } }
- By default, the bot checks the status of servers every four minutes.
- To modify this, change the variable
refreshEvery
to the number of minutes between every refresh. Use a floating point numeral if required.
Note: The bot being asynchronous, however, will require at least the number of servers times 2.5
seconds to fetch the statuses of all servers at once. This time interval can be reduced, but it is suggested that this remain as it is to prevent any malfunctioning.
Note, this applies only if you are running the bot a Linux machine. Here we are using CentOS.
- On your server, create a unit file under
/etc/systemd/system/homer-mc-bot.service
- Paste in the following conetents:
Description=Homer's Minecraft stats bot
After=network.target
[Service]
Type=simple
WorkingDirectory=/minecraft/bot/installation/directory
User=minecraft
Group=minecraft
ExecStart=/bin/node minecraft/bot/installation/directory
ExecStop=/bin/pkill -9 node
Restart=always
SyslogIdentifier=minecraft
[Install]
WantedBy=multi-user.target
There's no port specified for my Minecraft server
The standard port for Minecraft servers is typically 25565.
Contributions and improvements to the project are welcome! The following users helped by reviewing code and fixing my silly errors:
GNU GPL v3 or later