This is part of my build-your-own-x weekly warmup and I've chosen to build a Discord bot based of this guide Node.js: Create a Discord bot
I plan on deploying the bot to fly.io.
I've also found a lot of my weaknesses from starting this project
Namely:
- Using a different environment than what was written in the discord.js guide since I used Typescript instead of plain JavaScript for this project.
- Lack of Typescript familiarity (I assumed that I could wing it with my JS experience.)
- Lack of ESLint, Prettier and Husky Integration (I scoured through multiple sources just to get an environment that feels good enough to make this project which are listed below in the articles)
- How Node and Typescript will have import issues. Due to configuring my
tsconfig
to use abaseUrl
to ditch relative imports I expected that it would revert back to relative imports after transpilation. Turns out you need a path remapper for it.
- MODULE_NOT_FOUND when ts-node uses absolute imports
- How to use Typescript for Discord bots
- Use Absolute imports in Typescript
- Configuring Path Aliases
Missing Permissions and Intents are what caused friction when developing the bot. I've encountered the following:
-
Listening on
messageCreate
events. In order to enable this the client bot needs to haveGatewayIntentBits.GuildMessages
intent as well as permission to read messages from the Oauth 2 URL generator. Source -
Replying on
messageCreate
events. To make this work two intent bits are required, namelyGuildMessageTyping
andMessageContent
. You also have to enableRich Presence for Message Content
to preventmessage.content
from being null. Source -
As of what I've tried you can't send messages to threads directly. You have to use a Webhook as described in this setup and giving the bot permission to
Manage Webhooks
in the Discord Developer Portal.
- Just found out that there is a
collector
object that listens for messages for a specified time. Source