Using the Discord.js library, we're going to send our first message command!
Let's create a classic "hello world" message command and learn how to create a new client instance, enable the necessary gateway intents, listen for specific events, and respond to those events by accessing a "message object" and then sending a message back.
Instructor: [0:00] Let's go ahead and create a simple message command. First thing's first, we're going to need a couple more gateway intent bits, the first one being MessageContent. The second one is GuildMessages.
[0:29] Down below our event, we're going to create a new client, client on. The difference between once and on is once will only run once. The on means that it is able to be used at any point while our bot is running.
[0:52] This is going to be messageCreate. Message, turn this into a function.
[1:04] Then, if the message.content is equal to $hello, we want to reply to that message with 'world!. One last thing before we set that up, we head back over to our developer portal, over to bot, scroll down to our MessageContent intents.
[1:35] We need to turn this on if we're going to be sending messages this way. Hit save, head back over, save again. Now, if we head back over to our bot and we type $hello, our bot replies with 'world!.
Member comments are a way for members to communicate, interact, and ask questions about a lesson.
The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io
Be on-Topic
Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.
Avoid meta-discussion
Code Problems?
Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context
Details and Context
Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!