Michael-J-Scofield / discord-anti-spam

A simple discord anti spam node.js module to prevent spam on your discord server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Discord-anti-spam not deleting the spam messages and not assigning mute role

comicallybad opened this issue · comments

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

client.antiSpam = new AntiSpam({
    warnThreshold: 5, muteThreshold: 7, kickThreshold: 99, banThreshold: 99, maxInterval: 2000,
    warnMessage: '{@user}, Please stop spamming or you will be muted.',
    kickMessage: '**{user_tag}** has been kicked for spamming.',
    muteMessage: '**{user_tag}** has been muted for spamming.',
    maxDuplicatesWarning: 6, maxDuplicatesKick: 99, maxDuplicatesBan: 99, maxDuplicatesMute: 8,
    ignoredPermissions: ['MANAGE_NICKNAMES'],
    ignoreBots: true, verbose: false, muteRoleName: "Muted",
    removeMessages: true, removeBotMessages: false, ignoreBots: true,
    ignoredPermissions: ['MANAGE_NICKNAMES', 'MANAGE_MESSAGES'],
    verbose: false, muteRoleName: "Muted",
});

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
https://imgur.com/1fI2kNV

Desktop (please complete the following information):

  • Windows
  • Chrome
  • Latest

Additional context
I am not sure if I am setting this up right, I had issues before with not deleting messages, but not sending the warning message. Now after updating to the latest version, it is not deleting the spam messages, nor does it seem to mute the user after the warnings. As you can see from the code provided: removeMessages: true is enabled, same with muteThreshold: 7. So I am not sure why messages aren't being deleted. The warning is still working, but not removing the messages and muting the user.

The bot doesn't mute the user by adding a mute role now. It's using the timeout function by discord.

Okay that makes sense, but I still am confused as to why none of the spam messages are being deleted.

I will look into it.

Does your bot have the rights/permission to delete messages?

Yes, I even have my own bulk clear command where I can delete, of course up to that 2 week limit discord has. So I do know it can delete messages. Maybe I need to try to just use the default parameters on your documentation and then slowly change back to what I have and see if there’s a certain parameter I have that’s breaking it from deleting messages.

Would be great.

I will work on testing this when I have free time hopefully this weekend.

Okay, I have done some testing and I still am not getting messages deleted. Here is my code:

client.antiSpam = new AntiSpam({
    warnThreshold: 5, // Amount of messages sent in a row that will cause a warning.
    muteThreshold: 7, // Amount of messages sent in a row that will cause a mute
    kickThreshold: 99, // Amount of messages sent in a row that will cause a kick.
    banThreshold: 99, // Amount of messages sent in a row that will cause a ban.
    maxInterval: 2000, // Amount of time (in milliseconds) in which messages are considered spam.
    warnMessage: "{@user}, Please stop spamming or you will be timed out.", // Message that will be sent in chat upon warning a user.
    kickMessage: "**{@user}** has been kicked for spamming.", // Message that will be sent in chat upon kicking a user.
    muteMessage: "**{@user}** has been timed out for spamming.", // Message that will be sent in chat upon muting a user.
    banMessage: "**{@user}** has been banned for spamming.", // Message that will be sent in chat upon banning a user.
    maxDuplicatesWarning: 6, // Amount of duplicate messages that trigger a warning.
    maxDuplicatesKick: 99, // Amount of duplicate messages that trigger a warning.
    maxDuplicatesBan: 99, // Amount of duplicate messages that trigger a warning.
    maxDuplicatesMute: 8, // Ammount of duplicate message that trigger a mute.
    ignoredPermissions: ["MANAGE_NICKNAMES"], // Bypass users with any of these permissions.
    ignoreBots: true, // Ignore bot messages.
    verbose: true, // Extended Logs from module.
    ignoredMembers: [], // Array of User IDs that get ignored.
    unMuteTime: 10, // Amount of time (in minutes) a user will be muted for.
    removeMessages: true, // If the bot should remove all the spam messages when taking action on a user!
    modLogsEnabled: false, // If to enable modlogs
    modLogsChannelName: "mod-logs", // channel to send the modlogs too!
    modLogsMode: "embed",
    // And many more options... See the documentation.
});

Here is the outcome, still no message deletions. I have ensured the bot has manage message permissions in the guild and the specific testing channel I am using. I used almost the exact same parameters as the example, although I do not wish to kick or ban users for spamming, so I have set that to 99 as you can see above. Here is a picture of what happens:
delete not working

Edit Note: As well, the account spamming has no manage nicknames permissions

I just did another attempt with absolutely 0 changes to the example parameters, and still no messages were deleted

console.log(JSON.stringify(client.antiSpam.cache.messages));
[
    {
        "messageID": "940828172855959554",
        "guildID": "177579037319757824",
        "authorID": "709863865495584789",
        "channelID": "895166899439145000",
        "content": "spam",
        "sentTimestamp": 1644381316151
    },
    {
        "messageID": "940828174806294528",
        "guildID": "177579037319757824",
        "authorID": "709863865495584789",
        "channelID": "895166899439145000",
        "content": "spam",
        "sentTimestamp": 1644381316616
    },
    {
        "messageID": "940828176228159498",
        "guildID": "177579037319757824",
        "authorID": "709863865495584789",
        "channelID": "895166899439145000",
        "content": "spam",
        "sentTimestamp": 1644381316955
    }
]

It's got all the messages logged, it just isn't performing the deletion.

Since it's not deleting, I have just resorted to the events of warnAdd and muteAdd to delete the messages myself, however, sometimes the first 1-2 spam messages aren't logged in the cache and aren't deleted.

Okay. Thanks for the info, I will try to find the issue