Reputation: 131
Not sure What I am doing wrong here. I am trying to get my bot to only send this message if the user starts typing in the defined channel. I don't get errors the bot just doesn't send a message. Help Please!
bot.on("typingStart", (channel, user) => {
const bot_channel = "812180709401247658"
if (channel.id = bot_channel.id) {
message.send('wrong channel');
}
});
I have also tried:
bot.on("typingStart", (message , channel) => {
const bot_channel = "812180709401247658"
if (channel.id === bot_channel.id) {
message.send('wrong channel');
}
});
Upvotes: 1
Views: 549
Reputation: 31
Use this
bot.on("typingStart", (message, channel) => {
const channel = "812180709401247658"
if (message.channel.id != channel) {
return message.channel.send('You can only use this command in <#' + channel + '>');
}
});
if it still does not work use this
bot.on("message", (message) => {
const channel = "812180709401247658"
if (message.channel.id != channel) {
return message.channel.send('You can only use this command in <#' + channel + '>');
}
});
"!=" means isn't, so if channel isn't the one you selected it will return the message, simple
Upvotes: 0
Reputation: 567
A single equals sign =
is assignment. To perform comparison in JavaScript, use either the double equals sign or the triple equals sign. For most cases of comparison, you should use ===
. Your code should look like this then:
bot.on("typingStart", (channel, user) => {
const bot_channel = "812180709401247658"
if (channel.id === bot_channel.id) {
message.send('wrong channel');
}
});
Upvotes: 1