Skip to content

TheyCallMeLinux/Simple-Docker-Discord-MCbot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple-Docker-Discord-MCbot

Creating a Discord bot using discord.js to restart a Docker container on the host system involves several steps. Below is a complete guide to set this up, including the necessary code.

Setup Node.js and discord.js:

Setup Node.js and discord.js:

Ensure you have Node.js installed. Then, create a new project and install the necessary dependencies.

Setup & Dependencies

mkdir discord-docker-bot; cd discord-docker-bot
npm init -y
npm install discord.js@14 @discordjs/rest discord-api-types
npm install dotenv js-yaml 

Create a .env file

Create a .env file:

echo "DISCORD_TOKEN='YOUR_BOT_TOKEN'" > .env

This file will store your bot's token securely.

Modify the bot const

change these values according to your needs:

  • const dockerComposeFile = '/home/$user/docker-minecraft/docker-compose.yml';
  • const dockerContainerName = 'mcserver';
  • const YourGuildID = 'YOUR_GUILD_ID';

Run the bot

Execute your bot script using Node.js:

node bot.js

Don't forget !

You need to grab your actual bot key on https://discord.com/developers/applications/ then add in the .env file as shown bellow replace:

DISCORD_TOKEN=YOUR_BOT_TOKEN

'YOUR_GUILD_ID'

with your Discord server ID/bot token

Ensure the bot has the necessary permissions

to create commands, read messages, and add reactions.

Make sure Docker and docker-compose are installed and configured correctly

on the host system where this script runs. Adjust the variables located in bot.js (or requires additional flags.)

TODO

Error Handling

  • Wrap parts of code and try to handle potential errors.
  • even Better error handling

Command Cooldown

  • Implement cooldown for the main restart function to prevent spamming and avoid corruption.
  • Implement cooldown for other commands to maintain the bot's performance and prevent user spamming.

Poll Timeout

  • Set a timeout for your bot's polls, ending them if no reaction is received within that time.
  • Set a countdown before execution/poll closes

Poll Results Verification

  • Limit reactions per user to 1 for more accurate poll results.
  • Easily configure the number of reactions required

Command Usage Logging

  • Implement logging for all command usages to aid debugging.

Command Help

  • Create a /help command to provide brief descriptions of all available commands and improve user understanding.

Permissions Check

  • Before executing critical commands, check if the user has the necessary permissions. If not, return an error message.

Rate Limiting

  • Implement rate limiting on command usage to prevent abuse and overloading your bot.

Embeds

  • Utilize Discord Embeds to make bot's responses more visually appealing.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published