Skip to content

Discord on a self-hosted server

Create an application in the Discord Developer Portal. One application serves every Discord server connected to this GitNotify instance.

  1. Create a new application and give it a name.
  2. On General Information, copy the Application ID and Public Key.
  3. On Bot, create or reset the bot token and copy it once.
  4. Leave the privileged gateway intents off. GitNotify does not use the gateway or read messages.

Set these environment variables:

DISCORD_APPLICATION_ID=replace-with-the-application-id
DISCORD_PUBLIC_KEY=replace-with-the-public-key
DISCORD_BOT_TOKEN=replace-with-the-bot-token
DISCORD_INTERACTIVE=1

DISCORD_INTERACTIVE=1 adds incident ownership buttons. Leave it unset only if you do not want those buttons.

Apply the change with docker compose -f selfhosted/docker-compose.yml up -d gitnotify before you continue. Discord checks both endpoints below when you save them, and they answer 503 until the public key is loaded.

Set the Interactions Endpoint URL to:

https://gitnotify.example.com/discord/interactions

GitNotify also uses Discord Event Webhooks to record when the app is authorized for a server. Set the Event Webhooks endpoint to:

https://gitnotify.example.com/discord/events

Subscribe to the APPLICATION_AUTHORIZED event. The endpoint also safely acknowledges other event types. Both endpoints verify Discord's Ed25519 signature with DISCORD_PUBLIC_KEY and return 503 until that key is configured.

GitNotify does not register commands on startup. After the bot token, application ID, and ADMIN_TOKEN are set, call the admin route once:

Terminal window
ADMIN_TOKEN=$(grep '^ADMIN_TOKEN=' selfhosted/.env | cut -d= -f2-)
curl -fsS -X POST "http://127.0.0.1:8000/admin/discord/commands" \
-H "Authorization: Bearer $ADMIN_TOKEN"

The route replaces the application's global command set with GitNotify's current commands. Run it again after a release changes the command definitions.

Use this URL, replacing YOUR_APPLICATION_ID:

https://discord.com/oauth2/authorize?client_id=YOUR_APPLICATION_ID&scope=bot%20applications.commands&permissions=805391376&integration_type=0

The permission value 805391376 contains:

  • Manage Channels
  • Manage Roles
  • Manage Webhooks
  • View Channel
  • Send Messages
  • Embed Links
  • Read Message History

It does not include Administrator.

After installation, run /github connect as someone with Manage Server, choose repositories, and then run /setup. Other members can use /link to receive their own review and incident notifications. The commands and setup steps are the same as on the hosted GitNotify: see Discord.