Code Monkey home page Code Monkey logo

discord-anti-spam's People

Contributors

64ps avatar aadi0009 avatar androz2091 avatar anselal avatar arepp23 avatar bannerbomb avatar chlohe avatar dependabot-preview[bot] avatar dependabot[bot] avatar devtomatocake avatar doacola avatar joker314 avatar kieron avatar michael-j-scofield avatar miguelp25 avatar mraugu avatar notsugden avatar redsparr0w avatar scraayp avatar skaneprime avatar stijnvdkolk avatar theuntraceable avatar thomas-crane avatar y21 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

discord-anti-spam's Issues

error banEnabled & kickEnabled

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

Mutes not working at all

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?

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 | }

ask

Is it possible to make an exception for individual channels?

Missing of Discord Server

For easy support create a support server where peoples can easily discuss issues they are running into, etc.

Undefined variable KickedUsers

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))

Code Doesn't Work

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.

all event's except warnAdd are returning null for the member and reaction messages cannot be added as spam.

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.

warns people for saying one message

image
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.
});

all event's except warnAdd are returning null for the user and reaction messages cannot be added as spam.

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.

Module will not detect spam

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));

Cannot read property 'hasPermission' of null

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.

Catches everyone's messages rather than one person.

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.

Add exception to certain roles

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.

Default values are used instead of the provided configuration values.

Expected behaviour

The bot uses the provided configuration values.

Actual behaviour

The bot disregards some properties in the configuration and always uses the default values.

Why?

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.

;

)

Bot does not delete messages after ban

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.

Duplicates warnings dont work

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;

Help please

Bot treats multiple users as one, if person 1 send chat, then 2, then 3. Person 3 gets a warning

Add `ignoreOwner` options

Add an ignoreOwner option:

new antiSpam({
    ignoreOwner: true // Whether to ignore messages from the server owner
});

Actually, it's like true by default

Is it possible to parse value in a json file?

possible to include the values in a json file, as a sample:
{
"warnBuffer" : "3",
"maxBuffer" : "5",
"interval" : "logs",
"warningMessage" : "please stop spamming!",
"banMessage": "blablabla"
}

Issue

So I put the code in my bot but this error pops up exemptRoles
^^^^^^^^^^^^^^
Unexpected identifier

attachments and dublicates problems

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

I am getting ussye

`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

Duplicate Messages Issue

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.

add code to your

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

Doesn't work for 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.

error haspermission of none

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!

ban users only without roles

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

all event's except warnAdd are returning null for the user and reaction messages cannot be added as spam.

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.

Error

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

antispam is not defined, bot is not either

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

Invalid shorthand property initializer

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.