我正在尝试“调节”一个 channel ,在这个 channel 中应该只能发送某些命令,并且当他们发送的命令或消息不同于允许的命令或消息时,我会发送一条消息警告。我有条件的适度逻辑,但我的问题是我无法获得在该 channel 上发送的消息(在该特定 channel 上写的任何人)
执行代码时,它不会在控制台中显示任何内容,这意味着它无法识别他们在该 channel 中发送的消息:(
代码:
client.on("message", (message) => {
if (message.author.tag === "NAME#1234") {
if (message.content.startsWith(prefix + "on")) {
console.log(message.channel.id)
if (message.channel.id == "361344824500289538") {
//If the channel where they send the message has the id that I have set, then show me the messages that are sent
console.log(message.content)
} else {
console.log(message.content)
}
}
}
});
最佳答案
假设您想要一个仅在一个 channel 中使用的命令(对于名为“memes”的 channel ,这可能是/meme)。如果在别处使用该命令,机器人会说“此处不允许使用命令!”
这是代码:
client.on("message", message => {
if (message.content.startsWith('/meme') {
if (message.channels.find(c => c.name ===! 'memes') {
message.reply("Command Not Allowed Here!")
} else {rest of meme command script}
}
}
关于javascript - 想读取特定 channel 的消息时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54658774/