![](/img/trans.png)
[英]How do I make my discord bot send a message when a specific user plays a specific game?
[英]How can I make my discord bot only send a message if a user starts typing in a specific 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("typingStart", (channel, user) => {
const bot_channel = "812180709401247658"
if (channel.id === bot_channel.id) {
message.send('wrong channel');
}
});
用這個
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 + '>');
}
});
",=" 表示不是,所以如果頻道不是您選擇的頻道,它將返回消息,簡單
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.