Javascript 如果用户开始在特定频道中键入内容,如何使我的discord bot仅发送消息?
我不知道我做错了什么。我试图让我的机器人仅在用户开始在定义的频道中键入时发送此消息。我没有收到错误,机器人只是不发送消息。救命啊Javascript 如果用户开始在特定频道中键入内容,如何使我的discord bot仅发送消息?,javascript,discord,discord.js,bots,Javascript,Discord,Discord.js,Bots,我不知道我做错了什么。我试图让我的机器人仅在用户开始在定义的频道中键入时发送此消息。我没有收到错误,机器人只是不发送消息。救命啊 bot.on("typingStart", (channel, user) => { const bot_channel = "812180709401247658" if (channel.id = bot_channel.id) { message.send('wrong channel'); } }
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');
}
});
一个等号
=
是赋值。要在JavaScript中执行比较,请使用双等号或三等号。对于大多数比较情况,应使用==
。您的代码应该如下所示:
bot.on(“键入开始”(频道,用户)=>{
const bot_channel=“812180709401247658”
if(channel.id==bot\u channel.id){
message.send(“错误通道”);
}
});
使用此
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(“键入开始”,“消息,频道)=>{
const channel=“812180709401247658”
如果(message.channel.id!=通道){
返回message.channel.send('您只能在中使用此命令');
}
});
如果仍然不起作用,请使用此选项
bot.on("message", (message) => {
const channel = "812180709401247658"
if (message.channel.id != channel) {
return message.channel.send('You can only use this command in <#' + channel + '>');
}
});
bot.on(“消息”,(消息)=>{
const channel=“812180709401247658”
如果(message.channel.id!=通道){
返回message.channel.send('您只能在中使用此命令');
}
});
“!=”表示不是,因此,如果频道不是您选择的频道,它将返回消息,simple尝试了此操作,不幸的是,它仍然无效。另外,感谢您解释分配与比较!