Coder Social home page Coder Social logo

0n1udra / slime_server Goto Github PK

View Code? Open in Web Editor NEW
63.0 3.0 19.0 2.45 MB

Control Minecraft server and more with Python Discord bot.

License: GNU General Public License v3.0

Python 100.00%
discord-bot rcon tmux minecraft minecraft-server discord-py discordbot python3 python-3 python

slime_server's Introduction

Control Minecraft server with Discord bot.

  • Configure depending on if bot is on the same computer as server, or using RCON for remote control.
  • Interface with server using RCON, Tmux/Screen or subprocess. Some features are disabled if using RCON or Subprocess.
    • NOTE: Some features will not work if on Windows, you can use something like WSL.
    • Optionally run the bot and server inside the same or different Tmux/Screen sessions.
    • The bot can use Tmux/Screen to send commands to the server, or use the Python subprocess module to run and manage the server.
    • Some features depend on if you have read/write access to server files (server.jar, logs, property files, etc).
    • If using Tmux/Screen or subprocess to control the server, the bot has to send a xp command with a randomly generated number so the bot can read the output properly.
      • NOTE: This is disabled when using RCON.
      • If you have better ways so it doesn't clog up the logs, lmk!
  • Basic commands: say, kick, teleport, save, weather, and gamemode.
  • Show connection history, chat log, online players, banned, OP list, and whitelist.
  • World save backup and restore system. Also has server folder backup/restore feature. These features need direct access to server files.
  • Server autosave, start, stop, status, version, log, update server.jar (only with Vanilla or PaperMC), and edit server.properties.

TODO List

  • Discord user and role specific permissions for certain commands and/or command groups.
  • Be able to setup and change bot and server settings without having to edit user_config.json file.
  • Show command usage for more commands.

Requirements

Python Modules

Setup

  1. Create Discord bot in Discord Developer Portal. Scroll down for instructions or click here
  2. Setup Python venv (if using) and install libraries. Scroll down for instructions or click here.
  3. Update settings by editing user_config.json variables. Scroll down for more or click here
    • NOTE: JSON file uses double quotes for strings.
    • Also, Do NOT edit the example server config entry.
  4. Run python3 run_bot.py help, shows commands to setup tmux and/or run bot.
  • python3 run_bot.py makefolders - Create required folders if starting from scratch.
  • python3 run_bot.py startbot - Starts bot.
  • python3 run_bot.py attachbot - Attach to tmux/screen if using.
  • python3 run_bot.py startbot attachtmux
  1. Use ?setchannel or ?sc command to set channel id. This is optional, any command issued to the bot will update the channel_id, however you may not see an output for that command until reissued.
  2. Read through the help pages with ?help or ?help2 in Discord.
  3. Optionals:
  • Use ?serverscan command to add servers you manually put in the 'servers' folder.
  • You can use ?update to download latest .jar file (Downloads latest PaperMC by default, more details in slime_vars.py comments, line 63)

Commands

  • ?help, ?help2 - Help pages. First one is my custom embed layout, second one is default discord.py format.
  • ?start, ?stop, ?restart - Start/stop Minecraft server.
  • ?check - Check if server is online, and if console is reachable, if able.
  • ?status - Server information: status, version, motd, address/IP, players online, etc.
  • ?players - Show names of online players.
  • ?playerpanel - Common bot commands and functionality using discord.py components.
  • ?teleportpanel - Easy to use teleport panel. Includes return button to return teleported player to previous position.
  • ?playerlocate - Get xyz coords of player.
  • ?serverproperties - Show or edit properties in server.properties file.
  • ?worldbackup, ?worldrestore, ?serverbackup, ?serverrestore - Manage world and server backups.
  • ?serverlog, ?chatlog, ?connectionlog, ?botlog - Show logs for: server, just player chats, server connections and bot.
  • ?update - Update server .jar file.
    • The bot checks the server name and description configs to determine what flavor of server to get.
      E.g. If papermc is in the server description, it'll get the latest PaperMC jar from official site.
    • Currently working: vanilla, papermc
  • ?botupdate - Uses Git CLI to pull the latest update from Master branch.
    Note: Will not work if there's local changes. Either stash them or use git restore . in source folder.

User Configs

File Structure:

  • Either use python3 run_bot.py makefolders to create these folders or create your own and update the paths in configs.
    • Above command will create Games folder in your home directory if it doesn't exist. Then Minecraft, servers, world_backups, and server_backups inside.

Example folder structure:

Home (home_path, e.g. ~/ or C:\Users\0n1udra)
└─ Games
    └─ Minecraft (mc_path)
       ├─ servers (servers_path)
       │  ├─ papernc (server_path, e.g. ~/Games/Minecraft/servers/papermc)
       │  │  └─ server.jar
       │  └─ vanilla
       │     └─ server.jar
       ├─ server_backups
       │  ├─ papermc (server_backups_path)
       │  └─ vanilla
       └─ world_backups
          ├─ papermc (world_backups_path)
          └─ vanilla

Bot Configs:

  • use_pyenv, pyenv_activate_command - If using python virtual environment.
  • bot_launch_command - Set custom arguments when launching bot.
  • show_sensitive_info - Show or hide sensitive info in launch banner.
  • disabled_commands - Disable specific commands. Must put original command name not aliases if you want to completely disable it.
  • bot_token_filepath - Path to Discord token file.
  • command_prefix, case_insensitive - Discord command prefix, and command case insensitivity.
  • players_custom_status, custom_status_interval - Show players online and server ping in bot's custom status section.
    • use_custom_ping_address, custom_ping_address - Set a custom address for the ping section.
  • bot_use_tmux, bot_tmux_name, bot_tmux_pane - Run bot in a Tmux session.
    • NOTE: Set bot_tmux_name and server_tmux_name to the same to run them both in the same session. currently only supports the bot and one Minecraft server.
  • bot_use_screen, bot_screen_name - Run bot in a Screen session.
  • home_path, bot_source_path, mc_path, servers_path - Used for setting default configs for bot and servers.
  • user_config_filepath, bot_log_filepath - Miscellaneous variables needed for bot.
  • windows_compatibility - Bot will automatically detect if running on Windows system. This is Needed to adapt some commands to work for Windows, like starting Minecraft server.
  • windows_cmdline_start - Bot will prefix this to server_launch_command to start server.
  • selected_server, init - More miscellaneous configs needed for bot functionality.

Server Configs:

  • server_name, server_description, server_version - Basic server info.
    • NOTE: Bot will try to detect server version. If it doesn't work, you can set it manually. however, it might be overridden by the bot if it successfully detects a version.
  • server_address, server_port - Server domain/IP and port. Not needed, but some features may not work properly.
  • server_use_essentialsx - EssentialX plugin compatibility.
    • NOTE: Bot will use pong command instead of xp. See status_checker_command below for more.
  • server_files_access - If you are running the bot on the same system as the server, and it can access server files.
    • Needed for some features like world/server backup and restore, editing server.properties file, etc.
  • server_use_rcon, rcon_pass, rcon_port - RCON configs. Uses server_address.
  • server_use_tmux, server_tmux_name, server_tmux_pane - Run server in a Tmux session.
  • server_use_screen, server_screen_name - Run server using Screen.
  • server_use_subprocess - Run server using Python's subprocess module.
    • NOTE: The server will stop if the bot process is interrupted or killed.
  • server_launch_command - Command used to start server.
  • server_launch_path - Optionally set a custom path to the server executable (usually a .jar file).
  • startup_wait_time - This is just used to send a Discord message notifying how long the server takes to start.
  • save_world_wait_time - Set how long it takes for the server to save the world after sending a save-all command.
  • check_before_command - Only used if server_files_access is true. Sends a command to the server to check if it's reachable before sending actual command.
    • NOTE: This will clog your logs up. However, disabling this will mean the bot will not be sure if the server is reachable and if commands issued were successful or not.
    • status_checker_command" - The command that will be sent to server with a random number, then bot will check server logs to see if it was received. E.g. xp 0.123463246.
  • command_buffer_time - The time it takes for the server to run commands. Change this if your server is slower.
  • enable_autosave, autosave_interval - Send save-all command at specified minutes interval.
  • log_lines_limit - Set limit to how many log lines bot can read for some commands, like ?chatlog.
  • server_path, world_backups_path, server_backups_path, server_logs_path, server_log_filepath, server_properties_filepath - Bot will automatically set these based on mc_path. You can manually update them.
  • world_folders - Specify what world folders to backup.
  • useful_websites - For ?links command, which shows a Discord embed of these links.
  • server_ip - Bot will automatically set this if server_address is set.

Create Discord bot

  1. Go to: https://discord.com/developers/applications.
  2. Create New App:
  3. Go to OAUTH > URL Generator section to create invite link for the bot:

    Set the permissions:

    Invite bot to your server:
  4. Go to Bot section and get the token if you haven't already:
  5. While in the Bot section, scroll down and enable Message Content Intents:

Using Virtualenv or venv

Install Python3 venv:

sudo apt install python3-venv -y

Create Python Virtualenvt:

python -m venv ~/pyenvs/slime_server 

Activate new Python Virtualenv:

source ~/pyenvs/slime_server/bin/activate

Install required Python modules:

pip install -r requirements.txt

Screenshots

Screen Shot 2021-12-04 at 22 33 54

Screen Shot 2021-12-04 at 22 57 41

Screen Shot 2022-04-12 at 6 59 20 PM

Support me

slime_server's People

Contributors

0n1udra avatar deepsourcebot avatar jwhitbread avatar spongecade avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

slime_server's Issues

Changing the ammount of ram

How do I allocate mor then 2g to the server? I have 8gs on the machine im running it on and want to allocate them as well.

Getting Error about Valheim Password

Trying to start this up for a Minecraft server but seeing errors about valheim passwords?

Traceback (most recent call last):
  File "/home/ben/.local/lib/python3.9/site-packages/discord/ext/commands/bot.py", line 946, in _load_from_module_spec
    await setup(self)
  File "/opt/MoralBot/slime_server-master/source/cogs/personal.py", line 332, in setup
    await bot.add_cog(Other_Games(bot))
  File "/opt/MoralBot/slime_server-master/source/cogs/personal.py", line 66, in __init__
    self.valheim_text = f"{self.ip_text}\nPass: `{slime_vars.valheim_password}`"
AttributeError: module 'slime_vars' has no attribute 'valheim_password'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/ben/.local/lib/python3.9/site-packages/discord/client.py", line 409, in _run_event
    await coro(*args, **kwargs)
  File "/opt/MoralBot/slime_server-master/source/bot_files/slime_bot.py", line 24, in on_ready
    await setup(bot)
  File "/opt/MoralBot/slime_server-master/source/bot_files/slime_bot.py", line 479, in setup
    await bot.load_extension(f"cogs.{i[:-3]}")
  File "/home/ben/.local/lib/python3.9/site-packages/discord/ext/commands/bot.py", line 1012, in load_extension
    await self._load_from_module_spec(spec, name)
  File "/home/ben/.local/lib/python3.9/site-packages/discord/ext/commands/bot.py", line 951, in _load_from_module_spec
    raise errors.ExtensionFailed(key, e) from e
discord.ext.commands.errors.ExtensionFailed: Extension 'cogs.personal' raised an error: AttributeError: module 'slime_vars' has no attribute 'valheim_password'

Some commands doesnt work

Commands like ip or version works, but others such as players o weather not. How can i fixed it. Im running the bot on a machine and the server on a docker at the same machine.

meError: name 'server_ip' is not defined

Traceback (most recent call last):
File "/root/pyenvs/slime_server/lib/python3.8/site-packages/discord/ext/comman ds/bot.py", line 903, in invoke
await ctx.command.invoke(ctx)
File "/root/pyenvs/slime_server/lib/python3.8/site-packages/discord/ext/comman ds/core.py", line 855, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "/root/pyenvs/slime_server/lib/python3.8/site-packages/discord/ext/comman ds/core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: Nam eError: name 'server_ip' is not defined

This is the error I am getting The VARS are filled correctly. Not sure why this is failing.

Help

Hello i need Help installing this if possible .

"can't find window 1"

Hello, when I try to run the bot with tmux, I have a message "Can't find window 1". I don't understand why, so if anyone has a solution I'm interested ! And when I try to run discord_mc_bot I have this msg : "can't find session: mcserver". I hope someone has a solution, thanks !

??QUESTION??

i get some awefull of errors but when i check with pycharm no errors are thrown before i run : RUN_BOT.py this are my errors

pycharm error Slime_Server py DiscordBot

is this only for minecraft java ?

Hello
this bot features are amazing
thanks a lot for sharing <3
im new to this
can i run this bot with pmmp pocketmine serrver or its only for java ?
as i see rcon option in server configuring files in my hosting cpanel and im not sure if i can install other requiremnts u mentioned
so i asked here
sorry for taking from your time
thanks in advenced

Xp command giving error.

[10:58:53 INFO]: Incorrect argument for command
[10:58:53 INFO]: xp 0.7469874118303291<--[HERE]

paper 1.19.2

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.