This is an example application that provides a multi-stage Docker Discord Bot that runs in shards.

Overview

topggstatsupdater

This is an example application that makes it possible to create a fully Docker supported Discord Bot that runs in shards. You can run this application in multiple ways:

  • Local development without Docker
  • Local develepment with Docker Compose
  • Docker CLI Run
  • Run with Docker Compose
  • Run with Docker Swarm Stack
  • Run all shards in one service
  • Spread or split shards over multiple services

You can also create your own Docker image using Docker CLI or Docker compose.

It's all documented in this readme file.

This project provides a microservice that updates your TopGG statistics on an hourly basis. Sharding is supported. It's possible to run all shards (one or multiple) on one service or make each shard run on its own service (see README).

This project uses Docker, DiscordJS and TopGG and more.

Development server without Docker

Create file nodemon.json from template nodemon.json.example and fill in the TOKEN and TOPGG environment variables.

Run npm start for a dev server. The app will automatically reload if you change any of the source files.

Building with Docker CLI

Run docker build --rm -t <image> . to build the Docker image for production.

NOTE:

If you plan on deploying your image to another machine, make sure to push your image to a repo. Check out the Docker docs here if you want to use Docker Hub. (recommended)

Building and running the app with Docker Compose for development

Run docker-compose build to build the dev image.

NOTE:

You can skip build if you plan on using composer up to run it, because up is setup to automatically build it for you.

Create file .env from template .env.example and fill in the TOKEN and TOPGG environment variables.

Run docker-compose up to build and run the dev image.

Running the app with Docker Run

Run docker run --env TOKEN=<discord_token> --env TOPGG=<topgg_token> <image> to run the docker image.

Make sure to assign the following .env variables:

  • TOKEN
  • TOPGG

Make sure to use the same image you used when building your image.

Building the app with Docker Compose for production

Run docker-compose -f docker-compose.yaml -f docker-compose.prod.yaml build to build the docker image for production.

NOTE:

If you plan on deploying your image to another machine, make sure to push your image to a repo. Check out the Docker docs here if you want to use Docker Hub. (recommended)

NOTE:

Composer is not meant to run in production. It is only meant for development or building images. Make sure to read Getting started with swarm mode and check this if you want to use run your build image on a proper environment. (recommended)

Running the app with Docker Swarm

Create Swarm stack file

Run docker-compose -f docker-compose.yaml -f docker-compose.prod.yaml config to combine base and production compose file.

Suffix with > prod.yaml to output it in a file.

Copy this prod.yaml file to your production machine to run your stack on production.

Creating secrets

On the machine you're planning to run your Swarm stack on do:

Run echo <discord_token> | docker secret create TOKEN_FILE - to create TOKEN secret.

Run echo <topgg_token> | docker secret create TOPGG_FILE - to create TOPGG secret.

Make sure to change the following variables without <> to your personal keys:

  • discord_token
  • topgg_token

NOTE:

Creating secrets can be done in multiple ways and may differ depending on your OS. Make sure to read the Docker Documentation to find the best way on creating a secret in your situation.

Create file .env from template .env.example and leave TOKEN_FILE and TOPGG_FILE environment variables as they are.

Run Swarm stack file

Run docker stack up -c prod.yaml app --with-registry-auth to run the stack.

Split shards into multiple services

By default this app runs all shards on a single service. It can be changed so that every service runs its own separate shard.

This can be done with Swarm and Compose (dev and prod).

Change .env file from template .env.example and set SHARD_SPLITTED to 1 and TOTAL_SHARDS to the number of services/shards

Assign the amount of services in the docker-compose.yaml, docker-compose.override.yaml and docker-compose.prod.yaml and change the SHARD_ID environment in docker-compose.yaml accordingly, like in the example. The stack in this repo has four shards as example.

Either remove or add services to decrease or increase the amount of services/shards. Each service can only have one shard if splitting is active.

NOTE:

For your convenience, these following parts are commented out in the codebase, so you only have to remove the comment-symbols to make it work.

Replace services from docker-compose.yaml to the following:

services:
  discord-stats-0:
    <<: *discord-bot
    container_name: shard-0
    environment:
      SHARD_ID: 0
  discord-stats-1:
    <<: *discord-bot
    container_name: shard-1
    environment:
      SHARD_ID: 1
  discord-stats-2:
    <<: *discord-bot
    container_name: shard-2
    environment:
      SHARD_ID: 2
  discord-stats-3:
    <<: *discord-bot
    container_name: shard-3
    environment:
      SHARD_ID: 3

Development

Replace services from docker-compose.override.yaml if you to apply it on your Docker Compose to the following:

services:
  discord-stats-0:
    <<: *discord-bot
  discord-stats-1:
    <<: *discord-bot
  discord-stats-2:
    <<: *discord-bot
  discord-stats-3:
    <<: *discord-bot

Production

Replace services from docker-compose.prod.yaml if you to apply it on your Docker Swarm stack to the following:

services:
  discord-stats-0:
    <<: *discord-bot
  discord-stats-1:
    <<: *discord-bot
  discord-stats-2:
    <<: *discord-bot
  discord-stats-3:
    <<: *discord-bot

NOTE:

  • The amount of services must be equal to TOTAL_SHARDS in your .env file.

  • Make sure to start SHARD_ID from 0 and count up 1 each service.

  • If this is not configured properly, some shards will be skipped.

Run docker-compose -f docker-compose.yaml -f docker-compose.prod.yaml config > prod_splitted.yaml to create a new stack file and copy it to your production similarly done before like here.

Run docker stack up -c prod_splitted.yaml app --with-registry-auth to run the new split stack similarly done before like here.

Optional .env variables

DEBUG_MODE=0 Specify debug mode on or off.

restWsBridgeTimeout=5000 Maximum time permitted between REST responses and their corresponding websocket events - default 5000.

restTimeOffset=500 Extra time in milliseconds to wait before continuing to make REST requests (higher values will reduce rate-limiting errors on bad connections) - Default 500.

restRequestTimeout=15000 Time to wait before cancelling a REST request, in milliseconds - Default 15000.

restSweepInterval=60 How frequently to delete inactive request buckets, in seconds (or 0 for never) - Default 60.

retryLimit=1 How many times to retry on 5XX errors (Infinity for indefinite amount of retries) - Default 1.

Sources

Few resources used:

You might also like...

nganu bot, multi device based simple whatsapp-bot with social media downloader

nganu bot, multi device based simple whatsapp-bot with social media downloader

nganu A Simple Multi-Device WhatsApp Bot simple whatsapp-bot using baileys-md to download social media post and many features Install set instagram se

Nov 20, 2022

A simple & easy2use API for obtaining information about a discord user, discord bot or discord guild and their use for some purpose on websites!

discord-web-api A simple & easy2use API for obtaining information about a discord user, discord bot or discord guild and their use for some purpose on

Jun 28, 2022

Discord Neura - a Discord bot framework built on discord.js

Discord Neura Description Discord Neura is a Discord bot framework built on discord.js. Features Command Handler, Arguments, Preconditions and Listene

Mar 23, 2022

A discord bot made using discord.js and discord-player

A discord bot made using discord.js and discord-player

Musx A custom discord bot that can play music in your server 🎯 Add the bot to your server If you are looking for a music bot for your Discord server

Mar 28, 2022

This bot is a cool Discord bot made in discord.js using Node.JS

This bot is a cool Discord bot made in discord.js using Node.JS

Anti-Crosspost Discord Bot This bot is a cool Discord bot made in discord.js using Node.JS. It detects when a user cross-posts a message in multiple c

May 31, 2022

Co-Pilot is a discord Bot designed to be the all-in-one, open-source Discord bot that handles all your server needs.

Co-Pilot is a discord Bot designed to be the all-in-one, open-source Discord bot that handles all your server needs.

Welcome to Co-Pilot Bot repo! 👋 🤖 Co-Pilot (All-in-one Discord Bot) Co-Pilot is a discord Bot designed to be the all-in-one, open-source Discord bot

Nov 11, 2022

It is a discord bot bot which can play lofi song in different language 24/7. It has premium system and cool embed looks with buttons. It can play youtube songs, playlists. This bot code was made by Supreme#2401. It uses djs V12

It is a discord bot bot which can play lofi song in different language 24/7. It has premium system and cool embed looks with buttons. It can play youtube songs, playlists. This bot code was made by Supreme#2401. It uses djs V12

Lofi-Radio-Music-Bot It is a discord bot bot which can play lofi song in different language 24/7. It has premium system and cool embed looks with butt

Jan 2, 2023

New base bot WhatsApp 🈴 bukan self bot lagi atau buka bot yang bisa di pakai oleh bot sendiri 😎

New base bot WhatsApp 🈴 bukan self bot lagi atau buka bot yang bisa di pakai oleh bot sendiri 😎

Installation • Thanks to • Donate Official Group Bot • Settings Instalasi Heroku Buildpack Click the deploy icon below ! heroku/nodejs https://g

Feb 9, 2022

Sharing the latest stellar Super Mario 64 runs verified on speedrun.com.

Sharing the latest stellar Super Mario 64 runs verified on speedrun.com.

SM64-twitter-bot Sharing the latest stellar Super Mario 64 runs verified on speedrun.com. https://twitter.com/SuperMario64Bot Requirements You will ne

Jul 14, 2022
Releases(1.0)
  • 1.0(Feb 6, 2022)

    1.0

    For the lack of good examples on the internet I've made this Git Repo for my own example bot.

    This is an example application that makes it possible to create a fully Docker supported Discord Bot that runs in shards. It's multi-stage and you can run this application in multiple ways:

    • Local development without Docker
    • Local develepment with Docker Compose
    • Docker CLI Run
    • Run with Docker Compose
    • Run with Docker Swarm Stack
    • Run all shards in one service
    • Spread or split shards over multiple services
    Source code(tar.gz)
    Source code(zip)
Discord-Bot - You can use the discord bot codes that are updated in every video of the codes I use in the discord bot making series that I have published on my youtube channel.

Discord-Bot You can use the discord bot codes that are updated in every video of the codes I use in the discord bot making series that I have publishe

Umut Bayraktar 114 Jan 3, 2023
A multipurpose bot, a clan bot, a all in one bot. The one bot u need for ur server originally made as Milrato discord Bot and by Tomato6966.

Public Bot and Support Server! Invite the Public Version of this Bot so you don't need to host it by yourself or join my Discord server to get a custo

Tomato6966 472 Dec 25, 2022
Bot WhatsApp multi device / multi perangkat menggunakan lib / api baileys-md. Give star ⭐

Requirements • Installation • Thanks to • Official Group Bot • Donate Information Chika-Md adalah bot yang awalnya memakai base dari Hisoka-Morou. Chi

Riy 57 Dec 25, 2022
Aeona is a multi-purpose discord bot ready to skill up and boost up your Discord server! It has an State of the Art AI chatbot to make sure you never feel bored!

Aeona | Chatbot Aeona is an ever-growing multipurpose bot; primarily a fun chatbot you can converse with, but also showcases a wide range of fun comma

null 29 Jan 9, 2023
Gitlift Discord Bot is a discord bot which is listening Discord Messages to reply with user gitlift profile and total contributions.

Remoklify - Gitlift Discord Bot Gitlift Discord Bot is a discord bot which is listening Discord Messages to reply with user gitlift profile and total

Remoklify 3 Mar 20, 2022
About Discord bot draft that does not contain ready-made commands, compatible with discord.js v14. Create your own discord bot with this command handler.

discordJS-V14 About Discord bot draft that does not contain ready-made commands, compatible with discord.js v14. Create your own discord bot with this

Umut Bayraktar 36 Dec 28, 2022
null 8 Nov 4, 2022
whatsapp api to remote your whatsapp device. Support multi device, multi client. Still update to more feature. Please fork, star, donate and share.

Ndalu-wa-client DEPENDENCIES : { "@adiwajshing/baileys": "^4.2.0", "@adiwajshing/keyed-db": "^0.2.4", "axios": "^0.27.2", "body-parser

null 29 Jan 4, 2023
A multi-purpose discord bot, that has 100+ commands. Includes 🎶 Music, 📷 Image Generation, 📊 Leaderboard, and more!

Cleckzie An open-source, multi-purpose discord bot, made with JavaScript. Has useful categories like: ?? Music - filter, seek, queue, volume and more.

null 42 Jul 2, 2022
A multi-purpose assistant bot for Discord to make your server a better place.

━━━━━━ ❖ ━━━━━━ Rieko ?? FEATURES To be filled. ?? TIP JAR If you enjoyed it and would like to show your appreciation, you may want to tip me here. It

Jan Leigh Muñoz 3 May 23, 2022