Reputation: 11
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
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
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