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

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Crafty Controller Discord bot

GitHub License GitHub top language GitHub contributors GitHub Release Date 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

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

Roadmap

  • Server Restart: Restart the server
  • Server Backup: Create a backup of the server
  • 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

    INFO: 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.

  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:

  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

    INFO: 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 / Administration" permission, but this is not recommended for security reasons.

  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.

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:0.1

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

services:
  crafty-bot:
    image: twoplay/craftybot:0.1
    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 create a .env file in the root directory of the project and add the following environment variables:

SERVER_URL=
DISCORD_TOKEN=
CRAFTY_TOKEN=

#For the login command (optional)
USERNAME=
PASSWORD=

Start the bot

python main.py

Replace YOUR_DISCORD_TOKEN with your Discord bot token and YOUR_MONGO_URI with your MongoDB connection string.

Usage

Slash Commands (Beta)

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 or /bot_help

Command (>)

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

  >help or >bot_help

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.