Michael-J-Scofield / discord-anti-spam

A simple discord anti spam node.js module to prevent spam on your discord server
MIT License
146 stars 53 forks source link

Can you make it so I can add embeds? #160

Closed FxckingAngel closed 2 years ago

FxckingAngel commented 2 years ago

const antiSpam = new AntiSpam({ warnThreshold: 3, muteThreshold: 4, maxInterval: 2000, warnMessage: "{@user}, Please stop spamming", muteMessage: [em], //That's the embed maxDuplicatesWarning: 6, maxDuplicatesMute: 8, ignoredPermissions: ["ADMINISTRATOR"], ignoreBots: true, verbose: true, ignoredMembers: [], unMuteTime: 10, removeMessages: true, modLogsEnabled: false, modLogsChannelName: "mod-logs", modLogsMode: "embed", });

Scraayp commented 2 years ago

Have you tried putting it out of a array?

FxckingAngel commented 2 years ago

No I will try

FxckingAngel commented 2 years ago

I does not work with or without the array.

Scraayp commented 2 years ago

Can you send the embed code also

FxckingAngel commented 2 years ago

var em = new Discord.MessageEmbed() .setTitle(Muted!) .setDescription(Admin has muted you!) .setColor(800080) .setImage("https://i.pinimg.com/originals/93/4a/c2/934ac2e1254bfe067aff258f92260310.gif")

Scraayp commented 2 years ago

I'll look into this later today.

FxckingAngel commented 2 years ago

also here error sorry for not giving all info before asking

if (typeof data !== 'string') throw new error(errorMessage);
                                    ^

RangeError [EMBED_DESCRIPTION]: MessageEmbed description must be a string.

Scraayp commented 2 years ago

Oh. Ye that explains alot

FxckingAngel commented 2 years ago

This may work! message.channel.send({ embeds: this.format(this.options.muteMessage, message}))

FxckingAngel commented 2 years ago

for a catch

comicallybad commented 2 years ago

You can simply rely on the packages events... like warnAdd on that event:

antiSpam.onEvent("warnAdd", (member) => {
   //create your embed in here and send it to the log channel, or whichever channel you want.
   //in my case here is my code:
    const logChannel = member.guild.channels.cache.find(c => c.name.includes("mod-logs"));
    if (logChannel) {
        const embed = new MessageEmbed()
            .setColor("#ff0000")
            .setTitle("Member Warned")
            .setThumbnail(member.guild.me.user.displayAvatarURL())
            .setFooter({ text: member.guild.me.displayName, iconURL: member.guild.me.user.displayAvatarURL() })
            .setTimestamp()
            .setDescription(stripIndents`
            **Warned member:** ${member} (${member.id})
            **Warned By:** ${member.guild.me}
            **Reason:** Spam`)
        logChannel.send({text: '', embeds: embed});
    }
});
Scraayp commented 2 years ago

@FxckingAngel Have you tried to using an actual string?

 var em = new Discord.MessageEmbed()
        .setTitle("Muted!")
        .setDescription("Admin has muted you!")
        .setColor(800080)
        .setImage("https://i.pinimg.com/originals/93/4a/c2/934ac2e1254bfe067aff258f92260310.gif")
FxckingAngel commented 2 years ago

sorry for late reply they both work but for the first one need to fix this

antiSpam.on("warnAdd", (member) => {
    const logChannel = member.guild.channels.cache.find(c => c.name.includes("mellie-logs"));
    if (logChannel) {
        const embed = new MessageEmbed()
            .setColor("#800080")
            .setTitle("Member Warned")
        .setThumbnail(member.guild.me.user.displayAvatarURL())
            .setFooter({ text: member.guild.me.displayName, iconURL: member.guild.me.user.displayAvatarURL() })
            .setTimestamp()
            .setDescription(`
            **Warned member:** ${member} (${member.id})
            **Warned By:** ${member.guild.me}
            **Reason:** Spam`)
        logChannel.send({embeds: [embed]});
    }
});

yes but It won't send @Scraayp

FxckingAngel commented 2 years ago

You can simply rely on the packages events... like warnAdd on that event:

antiSpam.onEvent("warnAdd", (member) => {
   //create your embed in here and send it to the log channel, or whichever channel you want.
   //in my case here is my code:
    const logChannel = member.guild.channels.cache.find(c => c.name.includes("mod-logs"));
    if (logChannel) {
        const embed = new MessageEmbed()
            .setColor("#ff0000")
            .setTitle("Member Warned")
            .setThumbnail(member.guild.me.user.displayAvatarURL())
            .setFooter({ text: member.guild.me.displayName, iconURL: member.guild.me.user.displayAvatarURL() })
            .setTimestamp()
            .setDescription(stripIndents`
            **Warned member:** ${member} (${member.id})
            **Warned By:** ${member.guild.me}
            **Reason:** Spam`)
        logChannel.send({text: '', embeds: embed});
    }
});

This works just fix it like mine above https://github.com/Michael-J-Scofield/discord-anti-spam/issues/160#issuecomment-1049491176

Scraayp commented 2 years ago

That doesn't fix the issue why the warnMessage option already doesn't give the option to add the embeds.

ddemile commented 2 years ago

Hello, i have read the code of the module and i have find this lines that make the crash when you using embeds messages (you need to a .content a the end of the this.format())

222 if (embed.description) embed.setDescription(embed.description) 223 if (embed.title) embed.setTitle(embed.title) 224 if (embed.footer && embed.footer.text) embed.footer.text = this.format(embed.footer.text, message) 225 if (embed.author && embed.author.name) embed.author.name = this.format(embed.author.name, message)

Scraayp commented 2 years ago

Hello, i have read the code of the module and i have find this lines that make the crash when you using embeds messages (you need to a .content a the end of the this.format())

222 if (embed.description) embed.setDescription(embed.description) 223 if (embed.title) embed.setTitle(embed.title) 224 if (embed.footer && embed.footer.text) embed.footer.text = this.format(embed.footer.text, message) 225 if (embed.author && embed.author.name) embed.author.name = this.format(embed.author.name, message)

I already found out :). It's in my work in progress branch.

But thank you for letting know!

Scraayp commented 2 years ago

A option to add embeds was added in v2.8.0. Please see https://discord-anti-spam.js.org for more information!