💻
discordjsguide
  • Intro
  • How to use this guide
  • Starting and hosting your bot
    • Getting your application ready
    • Making your bot online
  • Hosting your bot 24/7
    • Glitch
  • Basic Guides
    • Making your first command
    • making a command handler
Powered by GitBook
On this page
  • How do command works?
  • Getting stuff ready
  • Adding more commands

Was this helpful?

  1. Basic Guides

Making your first command

PreviousGlitchNextmaking a command handler

Last updated 5 years ago

Was this helpful?

All of the following guide will be on the index.js file we created in the previous guide

How do command works?

Here is a basic system that how command work:

1. Player type in a command
2. The bot fetch the command
3. the bot finds the appropriate code
4. run the code

Getting stuff ready

To start, we will be using the . Message event emits whenever a message is sent in a server. So go ahead and type in the code below:

index.js
client.on("message", msg => {
    
})

We will be writing in line 2 of the code from now on.

Next, we will be getting message content that is sent in the server and validate it.

It is suggeted to put a prefix to the command. A prefix is what comes before a command, in the following example, L! is the prefix

index.js
if(msg.content === "L!ping"){
    msg.channel.send("Pong")//using msg.channel.send will send a message to the current channel
}

Adding more commands

To add more commands, just simply copy paste the if statement. Here is an example:

client.on("message", msg => {
if(msg.content === "L!ping"){
    msg.channel.send("Pong")//using msg.channel.send will send a message to the current channel
}
if(msg.content === "L!help"){
    msg.channel.send("Help command")//using msg.channel.send will send a message to the current channel
}
})
message event