panchester
panchester

Reputation: 335

How to make my discord bot only work in a chat?

I am using discord.js to implement a bot in the discord. When I use a command in any channel in my server, my bot responds to it, but I would like that my bot only worked if someone was sending the commands inside a private chat with the bot, how do I do that?

Upvotes: 0

Views: 327

Answers (2)

Octagonal T
Octagonal T

Reputation: 404

If you only want it to work between DMs, do

if (!message.channel.type == `dm`) return;

//other commands

Upvotes: 1

Jakye
Jakye

Reputation: 6625

You can check if the message was sent in a certain channel by checking the Message.channel.id property.

client.on("message", message => {
    if (message.channel.id !== "ChannelID") return false;

    // Execute your commands here
});

Upvotes: 0

Related Questions