不确定我在这里做错了什么。我试图让我的机器人仅在用户开始在定义的频道中输入时发送此消息。我没有收到错误,机器人只是不发送消息。请帮忙!
bot.on("typingStart", (channel, user) => {
const bot_channel = "812180709401247658"
if (channel.id = bot_channel.id) {
message.send('wrong channel');
}
});
我也试过:
bot.on("typingStart", (message , channel) => {
const bot_channel = "812180709401247658"
if (channel.id === bot_channel.id) {
message.send('wrong channel');
}
});
答案 0 :(得分:1)
单个等号 =
是赋值。要在 JavaScript 中执行比较,请使用双等号或三等号。对于大多数比较情况,您应该使用===
。您的代码应该如下所示:
bot.on("typingStart", (channel, user) => {
const bot_channel = "812180709401247658"
if (channel.id === bot_channel.id) {
message.send('wrong channel');
}
});
答案 1 :(得分:0)
使用这个
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 + '>');
}
});
如果还是不行就用这个
bot.on("message", (message) => {
const channel = "812180709401247658"
if (message.channel.id != channel) {
return message.channel.send('You can only use this command in <#' + channel + '>');
}
});
"!=" 表示不是,所以如果频道不是您选择的频道,它将返回消息,简单