appleGames
appleGames

Reputation: 11

bot responds to specific channel discord.js

How do I get a bot to respond only to a specific channel where I write a command

client.on('message', message => {
    if(message.content.startsWith("hey")) {
        message.channel.send('hello');
    } 
});

Upvotes: 0

Views: 1681

Answers (2)

Milo Moisson
Milo Moisson

Reputation: 124

You can use message.channel.id because the channel has a unique id, or you can check with message.channel.name but this is less unique, and you can have troubles with it.

Sou you can do something like:

const myChannelId = '0123456789'

client.on('message', message => {
    if(message.channel.id === myChannelId) return;
    if(message.content.startsWith("hey")) {
        message.channel.send('hello');
    } 
});

Upvotes: 0

MYousefi
MYousefi

Reputation: 1008

A simple approach is to check message.channel.name against the name of the authorized channel or list of channels. For example if (message.channel.name === "BotLounge"). For other information available about the channel please see https://discord.com/developers/docs/resources/channel

Upvotes: 1

Related Questions