我正在编写一个不和谐机器人,其中有一个命令可以查看用户在特定通道中发送的消息。在这个频道里,我们只能说“BLABLA”。我做了一个几乎可以工作的代码,如果我说“BLABLA”以外的话,机器人会删除消息,但如果我说例如:“嘿BLABLA”消息将不会被删除。
下面是我的代码:
bot.on("message", (msg) => {
if (msg.channel.id == "509789705651617793") {
if (!msg.content.toLowerCase().includes("bla")) {
msg.delete(1);
msg.author.send('You can only send "BLABLA" in <#509789705651617793>');
bot.channels
.get(`576073035476631563`)
.send(
`${msg.author}, tried to send something else than "blabla" in <#509789705651617793>, his message was: ${msg.content}`
)
.catch((err) => {
console.error("err");
});
}
}
});
2条答案
按热度按时间jslywgbw1#
您可以使用
Regular Expressions
并只允许发送字母b
、B
、l
、L
、a
、A
沿着String.prototype.startsWith()
,以确保消息以“BLA”开头。另一种方法是检查消息是否等于“BLABLA”。
lmvvr0a82#
您需要检查
message.content
的整个字符串是否有BLABLA