Druzai / Bot_Mc_discord

Discord bot to manage Minecraft server(s)
MIT License
3 stars 1 forks source link
discord-bot minecraft-java-edition python

bot icon

Bot for Minecraft Server in Discord

Build with pyinstaller and release

Main features

Warning

This bot designed to work only on 1 Discord server!

How bot converts mentions from Minecraft chat to Discord for game chat:

Minecraft Discord
@a @Minecrafters
@all @Minecrafters
@e @everyone
@everyone @everyone
@p @here
@here @here
@AnyRoleOrUserMention @AnyRoleOrUserMention

@Minecrafters - an optional role in Discord for managing the Minecraft server. If not stated then bot will mention @everyone.

Warning

Mentions from Minecraft mustn't contain @ in them!

Commands

If you want to see help on all bot's commands use help command when bot is running.

Note

Some commands will require an optional role or/and an admin role if you set them in bot config.

Languages

Supported 2 languages:

Requirements

Bot can automatically enable query and rcon in server.properties if file exists, but you can enable and enter them manually if you want.

Required bot intents

Build

Lib installation

Type in command prompt: (you must have requirements.txt and requirements-build.txt in root folder of the project)

pip install -r requirements.txt -r requirements-build.txt

For macOS you have to update certificates by running script /Applications/Python 3.XX/Install Certificates.command

Build with pyinstaller

It builds an executable file with bundled Python interpreter.

Type in command prompt make in root directory of the project to build it.

Executable file will be in %project_root_dir%/build_dist.

Build with shiv

It builds an executable archive, but it requires Python to launch!

Type in command prompt make build_pyz in root directory of the project to build it.

Executable archive will be in %project_root_dir%/build_dist. You can launch it with a double click or via Python - python Discord_bot.pyz.

Run

Warning

If you're running Minecraft server between versions 1.7.2 and 1.18.0 to avoid critical security vulnerability Log4Shell do instructions stated in this article!

Or check if your modded server already has a patch for it!

For game chat to work properly with languages other than English, you have to have argument -Dfile.encoding=UTF-8 when you're executing *.bat, *.cmd, Windows shortcut, *.sh or *.command script.

Windows

Just start bot executable file.

For the bot to properly start the Minecraft server you have to have *.bat or *.cmd script (in bot setting you can set name for this script) in your root Minecraft server directory! Example of file:

@echo off
rem java_runtime - path to java executable or its alias, default is 'java' alias
rem                If path has spaces, enclose the string in double quotes! For example: java_runtime="path to java runtime"
rem min_ram, max_ram - consists how many min and max GB you're allocating for server on start up
rem your_jar_file - jar file that starts up your server. It can be for vanilla: standard server.jar or for modded server: spigot.jar, forge.jar and etc.
rem java_parameters - parameters for Minecraft server
set java_runtime=java
set min_ram=1
set max_ram=3
set your_jar_file=server.jar
set java_parameters=
chcp 65001
cls
title Minecraft Server Console (%max_ram%Gb RAM)
%java_runtime% -Xms%min_ram%G -Xmx%max_ram%G %java_parameters% -Dfile.encoding=UTF-8 -jar %your_jar_file% nogui
exit /b

Also, if you don't want the server console to pop up in front of other windows at startup, you'll need to create shortcut by doing these steps:

After creating shortcut you can specify it as start file for bot instead of script in config setup.

Linux

On the desktop version of Linux just start bot executable file.

On the server version of Linux you have to start bot executable file using terminal with screen command! Example:

screen -dmS %your_session_name% %path_to_bot%/bot_executable_file

For the bot to properly start the Minecraft server you have to have *.sh script (in bot setting you can set name for this script) in your root Minecraft server directory! Example of file:

# java_runtime - path to java executable or its alias, default is 'java' alias
# min_ram, max_ram - consists how many min and max GB you're allocating for server on start up
# your_jar_file - jar file that starts up your server. It can be for vanilla: standard server.jar or for modded server: spigot.jar, forge.jar and etc.
# java_parameters - parameters for Minecraft server
java_runtime='java'
min_ram='1G'
max_ram='3G'
your_jar_file='server.jar'
java_parameters=''
exec ${java_runtime} -Xms${min_ram} -Xmx${max_ram} ${java_parameters} -Dfile.encoding=UTF-8 -jar ${your_jar_file} nogui

For server process bot will start a virtual terminal session via screen command with name according to the selected server's name. You can connect to it via screen -r %selected_server_session_name%. You can find server name in list of virtual sessions - screen -ls.

macOS

On macOS you should start bot executable file from terminal %path_to_bot%/bot_executable_file. Because if you just double-click on executable file, current working directory will be set as your home directory (~) and bot won't find config and key in most cases.

For the bot to properly start the Minecraft server you have to have *.command or *.sh script (in bot setting you can set name for this script) in your root Minecraft server directory! Example of file can be seen above in Linux section.

For server process bot will start a virtual terminal session via screen command with name according to the selected server's name. You can connect to it via screen -r %selected_server_session_name%. You can find server name in list of virtual sessions - screen -ls.

Localization

For adding or updating/fixing translations:

On Linux or macOS you may need to install gettext:

Tested platforms