Create your first Discord.js Bot Message Command

Lucas Minter
InstructorLucas Minter
Share this video with your friends

Social Share Links

Send Tweet

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!.