Skip to content

This is a small Discord bot for Minecraft Crafty Controller. You can start, stop servers and get status. Written in Python

License

Notifications You must be signed in to change notification settings

Two-Play/Crafty-Discord-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Crafty Controller Discord bot

GitHub License GitHub top language GitHub contributors Codacy Badge Codacy Badge

Table of Contents

  1. Introduction
  2. Features
  3. Roadmap
  4. Installation
  5. Usage
  6. Issues
  7. Contributing
  8. Support the Project
  9. Donations
  10. License

Introduction

Warning

This project is still in development and is not yet ready for production use. Please use it at your own risk.

This is a Discord bot that is designed to control the Crafty-Controller-4 server. This is useful if friends want to start a server and you want to control it from Discord. The bot is written in Python and uses the Discord.py library to interact with the Discord API.

Features

  • Server Status: Get the status of the server
  • Server Start: Start the server
  • Server Stop: Stop the server
  • Server Restart: Restart the server
  • Server List: Get a list of all servers

Roadmap

  • Server Backup: Create a backup of the server
  • Auto complete (slash commands): Auto complete the server ID
  • Web UI: Create a web interface for the bot

Installation

To install the bot, you will need to have a few things set up first.

Requirements

Server

You should have a Server to deploy this bot. You can use a VPS, local server or a Raspberry Pi. You can also use your own computer, but it is not recommended for availability reasons.

Crafty Controller user

You will need to create a new user (recommended) on the Crafty Controller server and obtain the user token. You can do this by following these steps:

  1. Go to your Crafty Controller server
  2. Click on the gear icon in the top right corner
  3. Click on "add user" and enter a name for your user (for example, "Crafty Bot")
  4. Fill in the required fields, select the desired permissions and click on "Save"
  5. Click on the pencil icon next to the user you just created
  6. Click on "API Key" and select the following permissions:
    • COMMANDS
    • TERMINAL
    • PLAYERS
  7. Enter a name for your user token (for example, "Crafty Bot Token")
  8. Click on "Create" to generate the user token
  9. Save your user token in a safe place (you will need it later)

Discord Bot

You will need to create a new Discord bot and obtain a bot token. You can do this by following these steps:

Important

I don't know if the permissions are correct, but you can try it out. If it doesn't work, please let me know. You can also use the "ALL" permission, but this is not recommended for security reasons.

  1. Go to the Discord Developer Portal
  2. Click on "New Application"
  3. Enter a name for your bot (for example, "Crafty Bot")
  4. Accept the terms and click on "Create"
  5. If you want to add an icon to your bot, click on "General Information" in the left-hand menu and then click on " Upload Image" under "App Icon"
  6. Click on "Bot" in the left-hand menu
  7. Under "username", you can change the name of your bot if you wish
  8. Disable the "Public Bot" option
  9. Click on "Reset Token" and confirm by clicking on "Yes, do it!"
  10. "Copy" under "Token" to copy your bot token
  11. Save your bot token in a safe place (you will need it later)
  12. Click on "OAuth2" in the left-hand menu
  13. Under "Scopes", select "bot"
  14. Under "Bot Permissions", select
    • View Channels
    • Send Messages
    • Create public threads
    • Use slash commands
    • Read Message History
    • Mention Everyone
  15. Click on "Copy" under "OAuth2 URL" to copy the invite URL
  16. Paste the invite URL into your web browser
  17. Select the server you want to invite the bot to
  18. Click on "Authorize"

Congratulations! Your bot has been invited to your server

Docker

Installing the bot using Docker is the easiest way to get started. To do this, you will need to have Docker installed on your system. If you do not have Docker installed, you can download it from the official Docker website.

Important

Replace YOUR_DISCORD_TOKEN with your Discord bot token, YOUR_CRAFTY_TOKEN with your Crafty Controller API token and YOUR_CRAFTY_SERVER_URL with the URL of your Crafty Controller server in the following format: https://your-crafty-server-IP:PORT.

To install the bot using Docker, you will need to run the following command in your terminal:

docker run -d --name crafty-bot -e DISCORD_TOKEN=YOUR_DISCORD_TOKEN -e CRAFTY_TOKEN=YOUR_CRAFTY_TOKEN -e SERVER_URL=YOUR_CRAFTY_SERVER_URL twoplay/craftybot:latest

Or you can use the following docker-compose.yml file:

services:
  crafty-bot:
    image: twoplay/craftybot:latest
    container_name: crafty-bot
    environment:
      - DISCORD_TOKEN=YOUR_DISCORD_TOKEN
      - CRAFTY_TOKEN=YOUR_CRAFT
      - SERVER_URL=YOUR_CRAFTY_SERVER_URL
    restart: unless-stopped

Python

If you would like to install the bot using Python, you will need to have Python 3.8 or higher installed on your system.

Clone the repository

git clone https://github.com/Two-Play/Crafty-Discord-bot.git

Change into the project directory

cd Crafty-Discord-bot

Create a virtual environment

python -m venv venv

Activate the virtual environment On Linux and macOS:

source venv/bin/activate

On Windows:

venv\Scripts\activate

Download the required dependencies

pip install -r requirements.txt

To run the bot, you will need to copy the .env.example file to a new file called .env and fill in the required fields. Only the DISCORD_TOKEN and CRAFTY_TOKEN fields are required to run the bot. If you want to use slash commands, you will need to fill in the GUILD_ID field as well.

Start the bot
```bash
cd core
python main.py

Replace YOUR_DISCORD_TOKEN with your Discord bot token and CRAFTY_TOKEN with your Crafty Controller API token.

Update

For updating the bot, you can use the following command:

# Change into the project directory and pull the latest changes
cd Crafty-Discord-bot
git pull

Usage

Slash Commands (Beta)

To use slash commands, you will need to set the GUILD_ID in the .env file. You can get the GUILD_ID by enabling the Developer Mode in Discord and right-clicking on the server name.

To get the slash commands, enter the following command:

  >clear
  >commands
  >sync

Hopefully, the bot will know the commands. It is still in beta, so it may not work as expected.

The bot supports slash commands. To use the slash commands, you will need to have the Use slash commands permission enabled for the bot.

  /help

Command (>)

Enter the following command to get a list of available commands:

  >help

To get the status of the server, enter the following command:

  >status

To start the server, enter the following command:

  >start [server_id]

replace [server_id] with the ID of the server you want to start. You can get the server ID by entering the >list command. For example:

  >start da459ce3-6964-46b8-bb21-1c3e753b6ba9

Issues

If you encounter any issues while using the bot, please report them on the GitHub Issues page.

Contributing

If you would like to contribute to the project, please follow these steps:

  1. Fork the repository
  2. Create a new branch (git checkout -b feature)
  3. Make your changes
  4. Commit your changes (git commit -am 'Add new feature')
  5. Push to the branch (git push origin feature)
  6. Create a new Pull Request
  7. Wait for your Pull Request to be reviewed
  8. Once your Pull Request is approved, it will be merged into the main branch
  9. Congratulations! You have successfully contributed to the project

Thank you for your contribution!

If you have any questions, please feel free to reach out to us

Support the Project

If you would like to support the project, you can do so by:

  • Giving the project a star on GitHub
  • Sharing the project with others
  • Contributing to the project
  • Donating to the project

Donations

If you would like to donate to the project, you can do so using the following methods:

Platform Link QR Code
Buy Me A Coffee Badge Buy Me a Coffee Buy Me a Coffee QR Code
PayPal Badge PayPal PayPal QR Code

Cryptocurrency Donations

You can click on the QR code to show a larger version of the QR code. GitHub does not support displaying large images in the README file.

Cryptocurrency Abbreviation
QR-Code
Address
Bitcoin Badge BTC bc1qk2xrz4mffeyh9dv8jm42vlejgmzft3adnweeqy
Ethereum Badge ETH Ethereum QR Code 0xBA615b7341C0d9aB4337dE4927B87e9E30fbE0b9
Litecoin Badge LTC Litecoin QR Code LNTn2u6svYMYswuwPSWTj41iXnxe4tP99i
Monero Badge XMR Monero QR Code 41hZYQV5uDzfiLCusRAxARST3hfTzGv7RNRyB92G1RZw64pvEQqwDo94zZHVxfvcmncLU1ockvJxbZBQToPqqDtBAor97sU

License

This project is licensed under the MIT License - see the LICENSE.md file for details.