Part 2:

Let’s finish this once and for all

Nithil Krishnaraj


Welcome to Part 2 of the tutorial. We’re going to be finishing up our bot by adding complex commands! Of course, make sure you have the prerequisites.


Resuming Step 3: Coding the bot

If you followed Part 1, your code should look like this:

Okay, so now, let’s create some more complex commands. If you’re making a moderation bot, the commands we make will be quite useful.

Let’s say someone on your server keeps deleting their messages. You can create a command on your bot that will alert that user to stop deleting their messages. Let’s create a .on()function that listens for any messages being deleted. It’s going to listen for "messageDelete" and will accept the parameter of msgso we can send messages in the channel.

client.on("messageDelete", msg => {// Code goes here})

Alright, now that we set up our function, we can make it send a message when the user deletes a message. For this, I am going to be using .reply()because I want the bot to specifically ping the user that’s deleting the messages.

msg.reply("stop deleting messages!!");

Once you add that, your code should look like this:

Let’s go on Discord and test out our function.

As you can see, it works! There is one problem though. The bot will send the warning message only for messages that have been sent after the bot’s initialization. This means that the bot can only read the messages after it. We want our bot to send a message for any message being deleted. To do that, we need to grant access to all the messages for our bot. In your client variable, add a property called partials.

const client = new Discord.Client({



Nithil Krishnaraj

Co-founder and Writer of TechTalkers. Learning about technology and photography are my passions!