- Go to Discord Developer Portal and create a application.
- Go to the Bot tab and save the token (reset the token if needed).
- Disable "Public Bot" option and enable the following options: Presence Intent, Server Members Intent and Message Content Intent.
- Replace
<BOT_ID>with the APPLICATION ID and run this in your browser:
https://discord.com/oauth2/authorize?client_id=<BOT_ID>&permissions=8&scope=bot
To get started you need to define some environment variables. This can be done by creating a .env file in the
root directory:
; The AnimeThemes URLs.
ANIMETHEMES_GRAPHQL=https://graphql.animethemes.moe
ARTIST_URL=https://animethemes.moe/artist
ANIME_URL=https://animethemes.moe/anime
; The config used to run this API.
API_HOST_NAME=http://api.animethemes.test/discord
API_HOST=localhost
API_KEY=
API_PORT = 3001
; The Bot Discord Token that you saved above.
DISCORD_TOKEN= ...
; The ID of the Discord Uploads Channel.
DISCORD_UPLOADS_CHANNEL_ID=1498006983935004682
; The ID of the Discord Trello Text Channel.
DISCORD_TRELLO_CHANNEL_ID=785620580384505867
; The enviroment of the application [production, development, staging, testing]
NODE_ENV=development
; Trello secret to validate trello webhooks.
TRELLO_SECRET=
TRELLO_CALLBACK_URL=http://api.animethemes.test/discord/trelloOnce the webhook is running you can tell Trello to send board update notifications to it. For that you can use Trello's REST API (and an HTTP client of your liking):
POST https://api.trello.com/1/tokens/<YOUR_TRELLO_TOKEN>/webhooks
Content-Type: application/json
{
"key": "<YOUR_TRELLO_KEY>",
"callbackURL": "<YOUR_WEBHOOK_URL>",
"idModel": "<BOARD_ID>",
"description": "My New Hook"
}- Replace
<YOUR_TRELLO_TOKEN>and<YOUR_TRELLO_KEY>with your Trello API token and key. - Replace
<YOUR_WEBHOOK_URL>with the URL that your webhook is running on. E.g.https://mydomain.com:3000. - Replace
<BOARD_ID>with the ID of the Trello board you want to receive updates for. You can get the ID for a board by appending.jsonto the board URL and reading theidfield. - You can set the
descriptionvalue to whatever you want.
To get a list of Trello board already added to the webhook, you can make a GET request to the same endpoint:
GET https://api.trello.com/1/tokens/<YOUR_TRELLO_TOKEN>/webhooks?key=<YOUR_TRELLO_KEY>Notice how you need to send the Trello API key as a query parameter instead of in the POST body.
You can also remove boards from webhook, by using the same endpoint, but doing a DELETE request instead:
DELETE https://api.trello.com/1/tokens/<YOUR_TRELLO_TOKEN>/webhooks/:id
Content-Type: application/json
{
"key": "<YOUR_TRELLO_KEY>"
}- Discord.js to communicate with Discord's API.