[英]How do i stop my discord.js bot from spamming the output
so I'm trying to make a discord bot for my discord server that will respond to people referencing inside jokes, but whenever I have the "christmas checker" on it will repeatedly spam.所以我正在尝试为我的不和谐服务器制作一个不和谐机器人,它将响应人们引用内部笑话的人,但是每当我有“圣诞节检查器”时,它就会反复发送垃圾邮件。 even if the input isn't part of the RegExp.
即使输入不是 RegExp 的一部分。
const Discord = require('discord.js');
const client = new Discord.Client();
var d = new Date();
var n = d.getMonth() + 1;
client.on('ready', () =>{
console.log('This bot is online!');
});
client.on('message', message => {
const regex1 = message.content.match(new RegExp(/fish in a tube|fish tube|fish in the tube|tube fish|where he goin/i));
if(regex1) {
message.channel.send(`Shut the hell up `+ message.member);
}
if(message.author.bot) return;
});
client.on('message', message => {
const regex2 = message.content.match(new RegExp(/merry christmas|its december|/i));
if(regex2){
message.channel.send('It ain\'t december yet buddy')
}
if(message.author.bot) return;
});
client.login('bot key removed');
Your second regex /merry christmas|its december|/i
will match anything because the third alternative has nothing entered.您的第二个正则表达式
/merry christmas|its december|/i
将匹配任何内容,因为第三个选项未输入任何内容。 Regex101 example , regex101's explanation: Regex101 示例,regex101 的解释:
1st Alternative merry christmas
第一个替代圣诞快乐
2nd Alternative its december
2nd Alternative 12 月
3rd Alternative — null , matches any position
第三个选择— null ,匹配任何位置
Try changing it to /merry christmas|its december/i
.尝试将其更改为
/merry christmas|its december/i
。
Also, you might want to change your code to only use one message handler.此外,您可能希望将代码更改为仅使用一个消息处理程序。 And put your check for a bot at the beginning of the handler, since if it's at the end it doesn't serve any purpose.
并将您的机器人检查放在处理程序的开头,因为如果它在最后,它就没有任何用途。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.