michael-j-scofield / discord-anti-spam Goto Github PK
View Code? Open in Web Editor NEWA simple discord anti spam node.js module to prevent spam on your discord server
License: MIT License
A simple discord anti spam node.js module to prevent spam on your discord server
License: MIT License
ERROR
`const AntiSpam = new DiscordAntiSpam({
kickEnabled: true,
banEnabled: true,
warnThreshold: 3,
banThreshold: 5,
kickThreshold: 30,
maxInterval: 2000,
warnMessage: "WARN",
banMessage: "BAN",
maxDuplicatesWarning: 7,
maxDuplicatesBan: 13,
maxDuplicatesKick: 30,
deleteMessagesAfterBanForPastDays: 7,
exemptPermissions: ["MANAGE_MESSAGES", "ADMINISTRATOR", "MANAGE_GUILD", "BAN_MEMBERS"],
ignoreBots: true,
verbose: false
});
AntiSpam.on("warnEmit", (member) => console.log(Attempt to warn ${member.user.tag}.
));
AntiSpam.on("warnAdd", (member) => console.log(${member.user.tag} has been warned.
));
AntiSpam.on("kickEmit", (member) => console.log(Attempt to kick ${member.user.tag}.
));
AntiSpam.on("kickAdd", (member) => console.log(${member.user.tag} has been kicked.
));
AntiSpam.on("banEmit", (member) => console.log(Attempt to ban ${member.user.tag}.
));
AntiSpam.on("banAdd", (member) => console.log(${member.user.tag} has been banned.
));
AntiSpam.on("dataReset", () => console.log("Module cache has been cleared."));
client.on("message", (msg) => {
AntiSpam.message(msg);
});`
2019-10-27T11:30:36.920122+00:00 app[worker.1]:/app/node_modules/discord-anti-spam/index.js:74 2019-10-27T11:30:36.920140+00:00 app[worker.1]: if (!banEnabled) return; 2019-10-27T11:30:36.920143+00:00 app[worker.1]: ^ 2019-10-27T11:30:36.920145+00:00 app[worker.1]: 2019-10-27T11:30:36.920147+00:00 app[worker.1]: ReferenceError: banEnabled is not defined
On the mute event, it just completely forgets to mute and skips over it. (with MuteEnabled: true,)
const AntiSpam = require('discord-anti-spam');
const antiSpam = new AntiSpam({
warnThreshold: 4,
kickThreshold: 8,
banThreshold: 12,
muteThreshold: 6,
maxInterval: 5000,
maxDuplicatesInterval: 5000,
muteRoleName: "Muzzled",
warnMessage: '{@user}, Please stop spamming.',
muteMessage: '{user_tag} has been muted for spamming.',
kickMessage: '{user_tag} has been kicked for spamming.',
banMessage: '{user_tag} has been banned for spamming.',
errorMessages: true,
kickErrorMessage: "Could not kick {user_tag} because of improper permissions.",
banErrorMessage: "Could not ban {user_tag} because of improper permissions.",
muteErrorMessage: "Could not mute {user_tag} because of improper permissions or the mute role couldn't be found.",
maxDuplicatesWarning: 7,
maxDuplicatesKick: 10,
maxDuplicatesBan: 10,
maxDuplicatesMute: 9,
exemptPermissions: ["MANAGE_MESSAGES"],
ignoreBots: true,
warnEnabled: true,
kickEnabled: false,
muteEnabled: true,
banEnabled: false
});
How do i make it delete spammed messages? i saw there was an update to toggle that but idk how, and i keep getting this error
| DiscordAPIError: Unknown User 0|bot | at /root/PB-master/node_modules/discord.js/src/client/rest/RequestHandlers/Sequential.js:85:15 0|bot | at /root/PB-master/node_modules/snekfetch/src/index.js:215:21 0|bot | at runMicrotasks (<anonymous>) 0|bot | at processTicksAndRejections (internal/process/task_queues.js:97:5) { 0|bot | path: '/api/v7/guilds/374071874222686211/members/696223811678240809', 0|bot | code: 10013, 0|bot | method: 'GET' 0|bot | }
Peoples have issues and I have a on-going pull request.
Is it possible to make an exception for individual channels?
For easy support create a support server where peoples can easily discuss issues they are running into, etc.
Here is kickedUsers.includes(message.author.id) instead of KickedUsers.includes(message.author.id)
Line 202
if (messageMatches === this.maxDuplicatesKick && !KickedUsers.includes(message.author.id))
So, I had a bot already made and thought it will be nice to have an anti-spam feature on it. Since I was new I used the example code. I changed the values of the code to what I wanted, then I tried it out with my friend. It didn't work for some reason and didn't give any error in the console. Please respond soon, Thanks.
Line 64 in 835f974
I will create a PR later if nobody wont.
Issue Solved
I am on Discord.js v12, not sure if that is the issue, as the package doesn't say anything about the Discord.js version. As well, I was hoping to mark reaction spamming as a form of spam, but on client.on('messageReactionAdd', =>(messageReaction, user)), I send antiSpam.message(messageReaction.message) and there is no luck. I do the same for messageReactionRemove, so it shouldn't be a time issue. As well, messageReaction.message is a regular message object return, just like client.on('message', (message)) object when compared in console log. The bot is still warning, kicking, and banning users upon spam, not sure why the event's are returning null if the events are actually working.
if you say one message it will warn you.
here's my code
const 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: "stop spamming or I'll whack your head off.", // Warning message send to the user indicating they are going to fast.
banMessage: "has been banned for spamming, anyone else?", // 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
deleteMessagesAfterBanForPastDays: 7 // Delete the spammed messages after banning for the past x days.
});
I am on Discord.js v12, not sure if that is the issue, as the package doesn't say anything about the Discord.js version. As well, I was hoping to mark reaction spamming as a form of spam, but on client.on('messageReactionAdd', =>(messageReaction, user)), I send antiSpam.message(messageReaction.message) and there is no luck. I do the same for messageReactionRemove, so it shouldn't be a time issue. As well, messageReaction.message is a regular message object return, just like client.on('message', (message)) object when compared in console log. The bot is still warning, kicking, and banning users upon spam, not sure why the event's are returning null if the events are actually working.
Since my bot is used on many servers I had to figure out a way to make it per guild which was pretty easy, but it does not seem to be working which is stupid
client.on("message", async message => {
let warnThresholdSetting = client.guildSpamSettings.get(message.guild.id, "warnThreshold")
let kickThresholdSetting = client.guildSpamSettings.get(message.guild.id, "kickThreshold")
let banThresholdSetting = client.guildSpamSettings.get(message.guild.id, "banThreshold")
let maxIntervalSetting = client.guildSpamSettings.get(message.guild.id, "maxInterval")
let maxDuplicatesWarningSetting = client.guildSpamSettings.get(message.guild.id, "maxDuplicatesWarning")
let maxDuplicatesKickSetting = client.guildSpamSettings.get(message.guild.id, "maxDuplicatesKic")
let maxDuplicatesBanSetting = client.guildSpamSettings.get(message.guild.id, "maxDuplicatesBan")
client.antiSpam = new AntiSpam({
warnThreshold: warnThresholdSetting, // Amount of messages sent in a row that will cause a warning.
kickThreshold: kickThresholdSetting, // Amount of messages sent in a row that will cause a ban.
banThreshold: banThresholdSetting, // Amount of messages sent in a row that will cause a ban.
maxInterval: maxIntervalSetting, // Amount of time (in milliseconds) in which messages are considered spam.
warnMessage: '{@user}, Please stop spamming.', // Message that will be sent in chat upon warning a user.
kickMessage: '**{user_tag}** has been kicked for spamming.', // Message that will be sent in chat upon kicking a user.
banMessage: '**{user_tag}** has been banned for spamming.', // Message that will be sent in chat upon banning a user.
maxDuplicatesWarning: maxDuplicatesWarningSetting, // Amount of duplicate messages that trigger a warning.
maxDuplicatesKick: maxDuplicatesKickSetting, // Amount of duplicate messages that trigger a warning.
maxDuplicatesBan: maxDuplicatesBanSetting, // Amount of duplicate messages that trigger a warning.
ignoreBots: false, // Ignore bot messages.
verbose: false, // Extended Logs from module. warnEnabled: true,
warnEnabled: true,
kickEnabled: true,
banEnabled: true
});
})
client.on('message', (message) => client.antiSpam.message(message));
TypeError: Cannot read property 'hasPermission' of null
at C:\Users\Manny\Documents\MCPZ\Watchdog\watchdog\node_modules\discord-anti-spam\index.js:162:64
at Array.some ()
at AntiSpam.message (C:\Users\Manny\Documents\MCPZ\Watchdog\watchdog\node_modules\discord-anti-spam\index.js:162:30)
at Client. (C:\Users\Manny\Documents\MCPZ\Watchdog\watchdog\main.js:47:12)
at Client.emit (events.js:315:20)
at MessageCreateAction.handle (C:\Users\Manny\Documents\MCPZ\Watchdog\watchdog\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (C:\Users\Manny\Documents\MCPZ\Watchdog\watchdog\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (C:\Users\Manny\Documents\MCPZ\Watchdog\watchdog\node_modules\discord.js\src\client\websocket\WebSocketManager.js:386:31)
at WebSocketShard.onPacket (C:\Users\Manny\Documents\MCPZ\Watchdog\watchdog\node_modules\discord.js\src\client\websocket\WebSocketShard.js:436:22)
at WebSocketShard.onMessage (C:\Users\Manny\Documents\MCPZ\Watchdog\watchdog\node_modules\discord.js\src\client\websocket\WebSocketShard.js:293:10)tShard.js:293:10) function without a catch
(node:2916) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an asynce the CLI flag --unhandle function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag
--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejectionshandled will terminate the_mode). (rejection id: 1)
(node:2916) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not
handled will terminate the Node.js process with a non-zero exit code.
I thought this was a personal 1 on 1 anti spam.
If it is then it does a really bad job because people can spam and if someone else talks while they are spamming it catches both people or just the person who ended up talking in the middle.
People who aren't even spamming get the warning message for spamming.
Is there an option for me to exempt certain roles, like an admin role? I don't want this to ban anyone with high roles.
If someone is caught spamming, it tells them to stop but doesn't delete the messages. It leaves them there. I want the spam messages to be deleted, even if the person isn't banned
The bot uses the provided configuration values.
The bot disregards some properties in the configuration and always uses the default values.
In the example in the readme there are several properties which we can use to change the warning and ban thresholds.
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.
// ...
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
// ...
});
Looking at the code we can see that the bot expects these properties to have a different name.
const warnBuffer = (options && options.prefix) || 3;
const maxBuffer = (options && options.prefix) || 5;
// ...
const maxDuplicatesWarning = (options && options.duplicates || 7);
const maxDuplicatesBan = (options && options.duplicates || 10);
The bot is expecting the properties prefix
and duplicates
to be present instead of the ones outlined in the readme.
I think it's more likely that this is a bug in the code instead of incorrect documentation in the readme, since according to the current code the same configuration values are used for both the warning and ban thresholds, which sounds like unintended behaviour.
Please push the GitHub version to npm ^^
How to make it not kick. I want it to only mute if spam
)
Your README.md is not equal to your source. Please update your README.md
When a user is caught spamming and is banned from the bot, the bot doesn't have anything in the reason for the ban. But most importantly, the bot doesn't delete the spammed messages, the messages should be deleted automatically if a user is banned but I'm not too sure if the bot is choosing not to delete the messages or what.
On my server it starts with the userid and not with a mention.
Here is a mistake in messageCache array. It must be messageCache.content instead of messageCache.message,
In messageMatches we are checking property content.
messageCache.push({ "message": message.content, "author": message.author.id });
let messageMatches = messageCache.filter((m) => m.content === message.content && m.author === message.author.id).length;
Bot treats multiple users as one, if person 1 send chat, then 2, then 3. Person 3 gets a warning
add a message.author.bot to all warning things
Add an ignoreOwner
option:
new antiSpam({
ignoreOwner: true // Whether to ignore messages from the server owner
});
Actually, it's like true
by default
possible to include the values in a json file, as a sample:
{
"warnBuffer" : "3",
"maxBuffer" : "5",
"interval" : "logs",
"warningMessage" : "please stop spamming!",
"banMessage": "blablabla"
}
So I put the code in my bot but this error pops up exemptRoles
^^^^^^^^^^^^^^
Unexpected identifier
after working with your code and rewriting it to my own needs, a few users and me found things that needed to be fixed. ( fixed the most for myself)
for example the attachments. If you send multiple attachments, the script detects it as dubplicates, because msg.content is empty when you only attach a file. So you will get warned.
also is this script a nice beginning but not useful for bots that run longer than one day and dont restart. Why you may ask, because (maybe I didnt saw it in the code ) you would get warned and maybe banned when you say "Hello" multiple times splited on a few hours or maybe days. My ideas where to clear the message history every 30min or also make a interval for dublicates.
dont get me wrong, Iam just trying to give advices to make the code better
`C:\Users\GangGamerAK\Desktop\Genbot\okay.js:16
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:74:10)
at Object.runInThisContext (vm.js:116:10)
at Module._compile (module.js:533:28)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
at Function.Module.runMain (module.js:605:10)
at startup (bootstrap_node.js:158:16)
at bootstrap_node.js:575:3` Help please
Greetings,
I've noticed that you have a "maxInterval" value which represents the amount of time in which messages are considered spam. However, there is no variable to evaluate the same thing but for duplicate messages. Which means that currently, when you've got something like this:
maxDuplicatesWarning: 5
maxDuplicatesKick: 10
Users will get kicked on the 10th duplicate message they send, even if it's over a day of messages in total. Which makes no sense at all, please add a "maxDuplicatesInterval" to serve the same function but for duplicate messages.
I've already tried fixing it myself by setting a timer to reset the cache at every 1 minute or so but just recently, the servers which host the bot had some downtime and it caused the bot to go on a kill spree basically and kick people because the cache wasn't getting reset.
hello I would like to use your anti spam to add code that adds level with the discord-leveling but I can not because I do not know how to do could you helped me
Hey, i have it like this
const Discord = require("discord.js");
var anti_spam = require("discord-anti-spam");
const bot = new Discord.Client()
module.exports = {
on: 'message',
code(message) {
anti_spam(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: 10000, // Amount of time in ms users can send a maximum of the maxBuffer variable before getting banned.
warningMessage: "stop spamming or I'll whack your head off.", // Warning message send to the user indicating they are going to fast.
banMessage: "has been banned for spamming, anyone else?", // 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
deleteMessagesAfterBanForPastDays: 7 // Delete the spammed messages after banning for the past x days.
});
}
}
Doesn't seem to do anything. Only says that messages have been logged after 11 of them were posted.
On line 162
If you have ignorebots on false it will give you the error: can't read haspermision of none!
For now the fix is to set ignorebots to true in the options!
Hi, why this script bans only without roles guest users?
If user has roles not work and send this "insufficient permission to kick user for spamming.".
Sorry, my English is not good. Please help. Thanks
I am on Discord.js v12, not sure if that is the issue, as the package doesn't say anything about the Discord.js version. As well, I was hoping to mark reaction spamming as a form of spam, but on client.on('messageReactionAdd', =>(messageReaction, user)), I send antiSpam.message(messageReaction.message) and there is no luck. I do the same for messageReactionRemove, so it shouldn't be a time issue. As well, messageReaction.message is a regular message object return, just like client.on('message', (message)) object when compared in console log. The bot is still warning, kicking, and banning users upon spam, not sure why the event's are returning null if the events are actually working.
C:\Users\MyPC\Desktop\New folder\bot.js:15
maxDuplicatesWarning = 20; // Maximum amount of duplicate messages a user can
send in a timespan before getting warned
^
SyntaxError: Unexpected token ;
at new Script (vm.js:51:7)
at createScript (vm.js:136:10)
at Object.runInThisContext (vm.js:197:10)
at Module._compile (module.js:626:28)
at Object.Module._extensions..js (module.js:673:10)
at Module.load (module.js:575:32)
at tryModuleLoad (module.js:515:12)
at Function.Module._load (module.js:507:3)
at Function.Module.runMain (module.js:703:10)
at startup (bootstrap_node.js:193:16)
The Error
Hello there
I tried editing your code a bit so that it mutes users instead of banning them,
but I can't even test it because I get these errors :
ReferenceError: antispam is not defined
at Object. (C:\Users\PC\Desktop\stuff\Bot_Discord\NodeJs\bot.js:14:1)
at Module._compile (internal/modules/cjs/loader.js:702:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
at Module.load (internal/modules/cjs/loader.js:612:32)
at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
at Function.Module._load (internal/modules/cjs/loader.js:543:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:744:10)
at startup (internal/bootstrap/node.js:238:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:572:3)
This one is when I don't touch anything, but when I modify the function and call it anti_spam, I get this error:
ReferenceError: bot is not defined
at Object. (C:\Users\PC\Desktop\stuff\Bot_Discord\NodeJs\bot.js:14:11)
at Module._compile (internal/modules/cjs/loader.js:702:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
at Module.load (internal/modules/cjs/loader.js:612:32)
at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
at Function.Module._load (internal/modules/cjs/loader.js:543:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:744:10)
at startup (internal/bootstrap/node.js:238:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:572:3)
So I guess I have to define bot now, unless I did the wrong thing with the antispam function,
But since I'm a real newbie I don't quite know how to define that bot, I should have to give it my bot's Id or something, but I dunno.
Could you please help me ?
Thanks
I made a new project to test ignoredGuilds on but it doesn't seem to work
ignoredGuilds: ['374071874222686211']
Hello, I have a little question. Is it possoble to execute code when someone hits the buffer? If so, how?
Any help is appreciated.
-JaxTheWolf
A-z all codes not working no error
c:\Users\etleg\Desktop\Bots\TrinityAlpha\bot.js:61
maxDuplicatesWarning = 7,
^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Invalid shorthand property initializer
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:152:10)
at Module._compile (module.js:624:28)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
at Function.Module.runMain (module.js:701:10)
at startup (bootstrap_node.js:194:16)
at bootstrap_node.js:618:3
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.