好的,我正在为我的不和谐服务器开发机器人。它将成为一个反垃圾邮件机器人。我发现这个用Node.JS编写的开源简单反垃圾邮件僵尸程序。
链接到项目,有两个链接:
当我尝试运行bot.js时,我在控制台中收到此错误:
maxDuplicatesWarning = 7,// Maximum amount of duplicate messages a user can send in a timespan before getting warned
^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Invalid shorthand property initializer
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:599:28)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
at Function.Module.runMain (module.js:676:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3
我已经尝试删除maxDuplicatesWarning行但是它只是给了我一个maxDuplicatesBan的错误。
这是我的bot.js:
const Discord = require("discord.js");
const client = new Discord.Client();
const prefix = "!"
client.on('ready', () => {
console.log(`Bot service launched. Bot ${client.user.tag} is successfully activated!`);
client.user.setStatus("dnd");
client.user.setGame('Fidget Spinner');
var anti_spam = require("discord-anti-spam");
antispam(bot, {
warnBuffer: 3, //Maximum amount of messages allowed to send in the interval time before getting warned.
maxBuffer: 5, // Maximum amount of messages allowed to send in the interval time before getting banned.
interval: 1000, // Amount of time in ms users can send a maximum of the maxBuffer variable before getting banned.
warningMessage: "stopp å spamme eller kutter jeg av deg kuken.", // Warning message send to the user indicating they are going to fast.
banMessage: "har blitt bannet for spamming, noen andre som vil?", // Ban message, always tags the banned user in front of it.
maxDuplicatesWarning = 7,// Maximum amount of duplicate messages a user can send in a timespan before getting warned
maxDuplicatesBan = 10 // Maximum amount of duplicate messages a user can send in a timespan before getting banned
});
client.login('private');
这是anti_spam.js:
const authors = [];
var warned = [];
var banned = [];
var messagelog = [];
/**
* Add simple spam protection to your discord server.
* @param {Bot} bot - The discord.js CLient/bot
* @param {object} options - Optional (Custom configuarion options)
* @return {[type]} [description]
*/
module.exports = function (bot, options) {
// Set options
const warnBuffer = (options && options.prefix) || 3;)
const maxBuffer = (options && options.prefix) || 5;)
const interval = (options && options.interval) || 1000;)
const warningMessage = (options && options.warningMessage) || "stop å spamme ellers kutter jeg av deg kuken.";
const banMessage = (options && options.banMessage) || "har blit bannet for spamming, noen andre som vil?";
const maxDuplicatesWarning = (options && options.duplicates || 7;)
const maxDuplicatesBan = (options && options.duplicates || 10;)
bot.on('message', msg => {
if(msg.author.id != bot.user.id){
var now = Math.floor(Date.now());
authors.push({
"time": now,
"author": msg.author.id
});
messagelog.push({
"message": msg.content,
"author": msg.author.id
});
// Check how many times the same message has been sent.
var msgMatch = 0;
for (var i = 0; i < messagelog.length; i++) {
if (messagelog[i].message == msg.content && (messagelog[i].author == msg.author.id) && (msg.author.id !== bot.user.id)) {
msgMatch++;
}
}
// Check matched count
if (msgMatch == maxDuplicatesWarning && !warned.includes(msg.author.id)) {
warn(msg, msg.author.id);
}
if (msgMatch == maxDuplicatesBan && !banned.includes(msg.author.id)) {
ban(msg, msg.author.id);
}
matched = 0;
for (var i = 0; i < authors.length; i++) {
if (authors[i].time > now - interval) {
matched++;
if (matched == warnBuffer && !warned.includes(msg.author.id)) {
warn(msg, msg.author.id);
}
else if (matched == maxBuffer) {
if (!banned.includes(msg.author.id)) {
ban(msg, msg.author.id);
}
}
}
else if (authors[i].time < now - interval) {
authors.splice(i);
warned.splice(warned.indexOf(authors[i]));
banned.splice(warned.indexOf(authors[i]));
}
if (messagelog.length >= 200) {
messagelog.shift();
}
}
}
});
/**
* Warn a user
* @param {Object} msg
* @param {string} userid userid
*/
function warn(msg, userid) {
warned.push(msg.author.id);
msg.channel.send(msg.author + " " + warningMessage);
}
/**
* Ban a user by the user id
* @param {Object} msg
* @param {string} userid userid
* @return {boolean} True or False
*/
function ban(msg, userid) {
for (var i = 0; i < messagelog.length; i++) {
if (messagelog[i].author == msg.author.id) {
messagelog.splice(i);
}
}
banned.push(msg.author.id);
var user = msg.channel.guild.members.find(member => member.user.id === msg.author.id);
if (user) {
user.ban().then((member) => {
msg.channel.send(msg.author + " " +banMessage);
return true;
}).catch(() => {
msg.channel.send("du har ikke rettigheter til å banne " + msg.author + " for spamming.");
return false;
});
}
}
}
有人可以帮我解决这个问题吗? 谢谢:D
NEW UPDATE!
现在我收到了这个错误:
const warnBuffer = (options && options.prefix) || 3;)
^
SyntaxError: Unexpected token )
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:599:28)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
at Module.require (module.js:579:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (C:\Users\Administrator\Desktop\Bots\fambot\bot.js:9:17)
答案 0 :(得分:1)
应该是:
antispam(bot, {
warnBuffer: 3, //Maximum amount of messages allowed to send in the interval time before getting warned.
maxBuffer: 5, // Maximum amount of messages allowed to send in the interval time before getting banned.
interval: 1000, // Amount of time in ms users can send a maximum of the maxBuffer variable before getting banned.
warningMessage: "stopp å spamme eller kutter jeg av deg kuken.", // Warning message send to the user indicating they are going to fast.
banMessage: "har blitt bannet for spamming, noen andre som vil?", // Ban message, always tags the banned user in front of it.
maxDuplicatesWarning: 7,// Maximum amount of duplicate messages a user can send in a timespan before getting warned
maxDuplicatesBan: 10 // Maximum amount of duplicate messages a user can send in a timespan before getting banned
});
您必须为:
而不是=
更新:
client.on('ready', () => {
console.log(`Bot service launched. Bot ${client.user.tag} is successfully activated!`)
});
答案 1 :(得分:0)
尝试使用utf-8字符集。我在我的项目中得到这样的结果