GithubHelp home page GithubHelp logo

michaeldivia / discord-minecraft-server-bot Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 1.0 39 KB

A Python Discord Bot to monitor and interact with a minecraft server running with screen

License: MIT License

Shell 7.33% Python 92.67%
discord-bot minecraft-server python discord-minecraft-bot

discord-minecraft-server-bot's Introduction

Linux Python Discord Bot for Minecraft Server

I created this bot to have a simple and easy way to get informations from a minecraft server and interact with it.

The_Bot

Key Features

  • Get dynamic informations about the server

    • Server Status
    • CPU Usage
    • Memory Usage
    • Player Count
    • Online Players Usernames
  • Interact with the service that runs the server

    • Restart
    • Shutdown
    • Start
  • Auto-restart the server if it crashes

  • Logs messages in a separate Discord Channel

Futur Key Features

  • Player Play time
  • Send command via Discord
  • Player Count as status
  • If there is a features that you would like to see, tell me about it !

Requirements:

Installing

This install is based on a FTB server with all the server files in the home directory of the user.

Install Screen

foo@bar:~$ sudo apt-get update
foo@bar:~$ sudo apt-get install screen

Download the files

Login as the user that runs the minecraft server and execute those commands :

foo@bar:~$ cd ~/
foo@bar:~$ wget https://github.com/Padi1111/discord-minecraft-server-bot/archive/refs/heads/main.zip
foo@bar:~$ unzip main.zip
foo@bar:~$ rm main.zip
foo@bar:~$ mv discord-minecraft-server-bot-main discord-minecraft-server-bot

Move the start script and edit it

Move the start script to the root of the minecraft server folder. In my case, this is the root home of the user.

foo@bar:~$ mv ~/discord-minecraft-server-bot/start.sh ~/.

You can then edit it to make it work with your minecraft server

foo@bar:~$ nano ~/start.sh

Edit the Bot

You can now edit the bot to your desire and configure it for your discord server. To do so, edit the file called user_settings.py in the discord-minecraft-server-bot folder.

foo@bar:~$ nano ~/discord-minecraft-server-bot/user_settings.py

Edit /etc/sudoers

To be able to run all the files in the Commands directory as sudo without giving any password we will be addind the scipts to our /etc/sudoers file. To do so, open it, as sudo, with your any editor :

foo@bar:~$ sudo nano /etc/sudoers

Go to this section :

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

And bellow it add the following command, making sure to change the [USERNAME] by the username of the user running the bot :

[USERNAME]  ALL=(ALL) NOPASSWD: /home/[USERNAME]/discord-minecraft-server-bot/Commands/service_stop.sh
[USERNAME]  ALL=(ALL) NOPASSWD: /home/[USERNAME]/discord-minecraft-server-bot/Commands/service_start.sh
[USERNAME]  ALL=(ALL) NOPASSWD: /home/[USERNAME]/discord-minecraft-server-bot/Commands/service_restart.sh

You can now save and close this file.

Create the Linux Service for the Minecraft Server

We will now be creating the service for the Minecraft Server.

foo@bar:~$ sudo nano /etc/systemd/system/minecraft-server.service

Copy paste this, making sure to change the [USERNAME] by the username of the user running the bot :

[Unit]

Description=Minecraft Server
After=network.target

[Service]

Type=simple
RemainAfterExit=true

WorkingDirectory=/home/[USERNAME]
User=[USERNAME]

Restart=on-failure

ExecStart=/usr/bin/screen -dmS mc-server bash start.sh

ExecStop=bash discord-minecraft-server-bot/stop.sh

[Install]

WantedBy=multi-user.target

Save and close this file.

Enable the serivce and start it :

foo@bar:~$ sudo systemctl enable minecraft-server.service
foo@bar:~$ sudo systemctl start minecraft-server.service

If everything whent well, your minecraaft server should now start. To check, login as the user that runs the server and execute this command :

foo@bar:~$ screen -ls

You should see something like this :

There is a screen on:
        2590603.mc-server       (15. 04. 23 16:00:18)   (Detached)
1 Socket in /run/screen/S-mcserver.

Create the Linux Service for the Bot

We will now be creating the service for the discord bot.

foo@bar:~$ sudo nano /etc/systemd/system/discord-minecraft-bot.service

Copy paste this, making sure to change the [USERNAME] by the username of the user running the bot :

[Unit]

Description=Discord Minecraft Bot
After=network.target

[Service]

Type=simple
RemainAfterExit=true

WorkingDirectory=/home/[USERNAME]/discord-minecraft-server-bot/
User=[USERNAME]

Restart=always
RestartSec=10

ExecStart=/usr/bin/python discord_bot.py


[Install]

WantedBy=multi-user.target

Save and close this file.

Enable the serivce and start it :

foo@bar:~$ sudo systemctl enable discord-minecraft-bot.service
foo@bar:~$ sudo systemctl start discord-minecraft-bot.service

If everything whent well, the bot should be online in your discord server and you should see the embedded message with all the informations about the minecraft server.

Screenshots

The_Bot_Restarting The_Bot_With_players The_Bot_logs

discord-minecraft-server-bot's People

Contributors

michaeldivia avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

sendokemsc

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.