Simple REST API to get presence of certain Discord users to integrate with tools for uptime monitoring.
This tool serves an API which returns different HTTP status codes based on the presence (online, offline, etc) of a Discord user. We use this to keep track of BitBot's uptime on Better Stack. The tool is written using the Bun (alternative JavaScript runtime to Node.js), with Elysia (web framework) and Discord.js.
Create a new application at https://discord.com/developers/applications.
On the 'Bot' tab, enable the Presence Intent and the Server Members Intent. You should see something like the image below when complete.
On the 'Installation' tab, under 'Installation Contexts', disable 'User Install' and in the 'Default Install Settings' section, add the bot
scope.
Oo the 'Installation' tab, use the link provided in the 'Install Link' section to add the bot to your server. Once installed, retrieve the bot token to include in your config, by going to the 'Bot' tab > 'Build-A-Bot' > 'Token' > 'Reset Token'.
The config file, discord-uptime.toml
, specifies which users should have their presences accessible via API, and other application-level config. discord-uptime.example.toml
has a sample of what a config should look like. Make a copy of this file, rename it to discord-uptime.toml
, then make edits as desired in your newly copied file to configure your bot. The server will crash on start up if something is wrong with your config file.
A Dockerfile
and Compose config have been created, so once you have your config file set up, docker compose up -d
should get you up and running.
First, make sure you have Bun installed. This tool won't run on Node due to using Bun's TOML library (which can be swapped out trivially if desired).
Open a terminal into this directory, then run bun install
to download dependencies. bun run dev
will run the bot with auto restarting when you change code (helpful for development). bun run start
will run the server without auto restarting (helpful for running on a server).