This bot can notify a server through a message when other bots go offline. It verifies when a bot has changed its presence status to offline
. The main use for this is to let users know when a bot becomes unusable. It also lets users know once the bot has gone back online and for how long it's been offline for.
This is mostly useful for server owners with self-hosted bots that need a way of getting notified when any one of their bots go offline. Ideally, this bot should be hosted on a high uptime service such as Heroku.
You will need to have a bot account on Discord. For this, head over to the developer portal and create an application. Inside the Bot tab, you need to enable the following Privileged Gateway Intents:
PRESENCE INTENT
SERVER MEMBERS INTENT
This is required because this bot depends on events like presenceUpdate
and guildMemberRemove
to function properly. You can enable these intents without the need to apply if your bot is in under 100 servers and/or is not verified. If your bot is verified, you will need to go through a whitelisting process where you'll need to justify the need for this information.
You can self-host this bot or deploy it on a service like Heroku for example. If you do decide to self-host, you'll need to have the following dependencies:
In order to self-host this bot, you'll need to clone this repository.
git clone https://github.com/moonstar-x/discord-downtime-notifier.git
Install the dependencies with:
npm ci --only=prod
Or, if you want to also install the devDependencies
:
npm install
After you have configured the bot, you can run it with:
npm start
To deploy to Heroku, you can click on the image below and login to your account.
You can now go back to your app's Overview, make sure you disable the web dyno and enable the bot dyno. Your bot should now be up and running. Remember you can always check your bot's console if you access the View Logs in the More dropdown menu.
You can start a container with the bot's image by running:
docker run -it -e DISCORD_TOKEN="YOUR DISCORD TOKEN" -e DISCORD_MONGO_URI="YOUR MONGO URI" moonstarx/discord-downtime-notifier:latest
Check configuration to see which environment variables you can use.
The following volumes can be used:
/opt/app/config
: The config folder for the bot, here you can use thesettings.json
file to configure the bot if you don't want to use environment variables.
You can inspire yourself from the following docker-compose.yml
file:
version: "3.9"
services:
db:
image: mongo:latest
volumes:
- ./data:/data/db
- ./mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro
environment:
- MONGO_INITDB_ROOT_USERNAME=ADMIN_USERNAME
- MONGO_INITDB_ROOT_PASSWORD=ADMIN_PASSWORD
bot:
image: moonstarx/discord-downtime-notifier:latest
depends_on:
- db
environment:
- DISCORD_TOKEN=YOUR_DISCORD_TOKEN
- DISCORD_PREFIX=d!
- DISCORD_MONGO_USERNAME=user
- DISCORD_MONGO_PASSWORD=password
- DISCORD_MONGO_DATABASE=database
- DISCORD_MONGO_HOST=db:27017
- DISCORD_OWNER_ID=123123123
- DISCORD_OWNER_REPORTING=false
- DISCORD_BROADCAST_REPORTING=true
- DISCORD_PRESENCE_REFRESH_INTERVAL=null
The mongo-init.js
file in the mongo
service is the DB initialization file. This runs only once when the container is first created (and no data is located in /data/db
). This file creates the user and the database. You may inspire yourself from the following one which creates the user user
and the database database
which are shown in the docker-compose.yml
file example.
db = db.getSiblingDB('database');
db.createUser({
user: 'user',
pwd: 'password',
roles: [
{
role: 'readWrite',
db: 'database'
}
]
});
Inside the config
folder, rename the file settings.json.example
to settings.json
and edit the file with your own Discord Token and other settings. If you don't have a Discord token yet, you can see a guide on how to create it here.
Your file should look like this.
{
"token": "YOUR_DISCORD_TOKEN",
"prefix": "$",
"mongo_username": "user",
"mongo_password": "pass",
"mongo_host": "localhost:27017",
"mongo_database": "mydb",
"mongo_uri": null,
"owner_id": "123123123",
"owner_reporting": false,
"broadcast_reporting": false,
"presence_refresh_interval": 900000
}
You may also configure these options with environment variables. The settings set with the environment variables will take higher precedence than the ones in the config JSON file.
This table contains all the configuration settings you may specify with both environment variables and the JSON config file.
Environment Variable | JSON Property | Required | Type | Description |
---|---|---|---|---|
DISCORD_TOKEN | token |
Yes. | string |
The bot's token. |
DISCORD_PREFIX | prefix |
No. (Defaults to: $ ) |
string |
The bot's prefix. Used for the commands. |
DISCORD_MONGO_USERNAME | mongo_username |
No. (Defaults to: null ) |
string or null |
The username of the mongoDB database. If you set this to null (or omit this option) you should fill out the MONGO_URI setting. |
DISCORD_MONGO_PASSWORD | mongo_password |
No. (Defaults to: null ) |
string or null |
The password of the mongoDB database. If you set this to null (or omit this option) you should fill out the MONGO_URI setting. |
DISCORD_MONGO_HOST | mongo_host |
No. (Defaults to: null ) |
string or null |
The host of the mongoDB database. This includes the IP and port. If you set this to null (or omit this option) you should fill out the MONGO_URI setting. |
DISCORD_MONGO_DATABASE | mongo_database |
No. (Defaults to: null ) |
string or null |
The database of the mongoDB database. If you set this to null (or omit this option) you should fill out the MONGO_URI setting. |
DISCORD_MONGO_URI | mongo_uri |
No. (Defaults to: null ) |
string or null |
The URI of the mongoDB database. You can set this to null (or omit this option) if you have added all the other mongo settings. This should have the shape: mongodb://user:pass@host:port/database . |
DISCORD_OWNER_ID | owner_id |
No. (Defaults to: null ) |
string or null |
The ID of the bot's owner. |
DISCORD_OWNER_REPORTING | owner_reporting |
No. (Defaults to: false ) |
boolean |
Whether the bot should send error reports to the owner via DM when a command errors. |
DISCORD_BROADCAST_REPORTING | broadcast_reporting |
No. (Defaults to: false ) |
boolean |
Whether the bot should send error reports to the guild owner when the status broadcast errors. |
DISCORD_PRESENCE_REFRESH_INTERVAL | presence_refresh_interval |
No. (Defaults to: 900000 ) |
number or null |
The time interval in ms in which the bot updates its presence. If set to null the presence auto update will be disabled. |
Note on
Required
: A required setting HAS to be in the JSON or environment variables.Note on
Defaults
: If a setting is missing from the JSON or environment variables, the default value takes place.Note on the mongo settings: If you specify
MONGO_URI
you don't need to specifyMONGO_USERNAME
,MONGO_PASSWORD
,MONGO_HOST
andMONGO_DATABASE
. This setting is mostly for when you have a mongo instance that requires you to have control over the connection URI.
Here's a list of all the commands for the bot.
Command | Alias | Required Permissions | Description |
---|---|---|---|
d!add <bot_mention> | d!a | MANAGE_GUILD |
Add a new bot to the tracking list. You must mention a bot. It will not track regular users. |
d!channel <channel_mention> | d!c | MANAGE_GUILD |
Update the channel where the broadcasting messages will be posted. The channel mentioned must be either a text channel or a news channel. If you don't mention any channel, the bot will reply with the currently set channel. |
d!list | d!l | MANAGE_GUILD |
List all the bots currently being tracked. |
d!remove <bot_mention> | d!r, d!delete, d!d | MANAGE_GUILD |
Remove a bot from the tracking list. You must mention a bot that is currently being tracked. |
d!help | d!h | Display a help message with all the available commands. |
Replace
d!
with your own prefix (in case you're self-hosting the bot).
You can add this bot to your server by clicking in the image below:
The bot's prefix for this instance is: d!
This bot was made by moonstar-x.