Constructor
new AntiSpam(optionsopt)
Properties:
Name | Type | Description |
---|---|---|
data |
AntiSpamData
|
Anti Spam cache data. |
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
options |
AntiSpamOptions
|
<optional> |
Client options. |
Example
const antiSpam = new AntiSpam({
warnThreshold: 3, // Amount of messages sent in a row that will cause a warning.
muteThreshold: 4, // Amount of messages sent in a row that will cause a mute
kickThreshold: 7, // Amount of messages sent in a row that will cause a kick.
banThreshold: 7, // 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.', // 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.
muteMessage: '**{user_tag}** has been muted for spamming.',// Message that will be sent in chat upon muting a user.
banMessage: '**{user_tag}** has been banned for spamming.', // Message that will be sent in chat upon banning a user.
maxDuplicatesWarning: 7, // Amount of duplicate messages that trigger a warning.
maxDuplicatesKick: 10, // Amount of duplicate messages that trigger a warning.
maxDuplicatesBan: 12, // Amount of duplicate messages that trigger a warning.
exemptPermissions: [ 'ADMINISTRATOR'], // Bypass users with any of these permissions.
ignoreBots: true, // Ignore bot messages.
verbose: true, // Extended Logs from module.
ignoredUsers: [], // Array of User IDs that get ignored.
muteRoleName: "Muted", // Name of the role that will be given to muted users!
removeMessages: true // If the bot should remove all the spam messages when taking action on a user!
// And many more options... See the documentation.
});
Methods
(async) message(message) → {Promise.<boolean>}
Checks a message.
Parameters:
Name | Type | Description |
---|---|---|
message |
Message
|
The message to check. |
Returns:
- Type:
-
Promise.<boolean>
Whether the message has triggered a threshold.
Example
client.on('message', (msg) => {
antiSpam.message(msg);
});
(private) reset() → {AntiSpamData}
Resets the cache data of the Anti Spam instance.
Example
const data = antiSpam.reset();
console.log(`Cleared a total of ${data.messageCache.length} cached messages.`);
Events
error
Emitted when the bot could not kick or ban a member.
Parameters:
Name | Type | Description |
---|---|---|
message |
Message
|
The Discord message |
error |
error
|
The error |
type |
string
|
The sanction type: 'kick' or 'ban' or 'mute' or 'warn' |
Example
antiSpam.on("error", (message, error, type) => {
console.log(`${message.author.tag} couldn't receive the sanction '${type}', error: ${error}`);
});
banAdd
Emitted when a member is banned.
Parameters:
Name | Type | Description |
---|---|---|
member |
GuildMember
|
The banned member. |
Example
antiSpam.on("banAdd", (member) => console.log(`${member.user.tag} has been banned.`));
kickAdd
Emitted when a member is kicked.
Parameters:
Name | Type | Description |
---|---|---|
member |
GuildMember
|
The kicked member. |
Example
antiSpam.on("kickAdd", (member) => console.log(`${member.user.tag} has been kicked.`));
muteAdd
Emitted when a member is muted.
Parameters:
Name | Type | Description |
---|---|---|
member |
GuildMember
|
The muted member. |
Example
antiSpam.on("muteAdd", (member) => console.log(`${member.user.tag} has been muted.`));
warnAdd
Emitted when a member is warned.
Parameters:
Name | Type | Description |
---|---|---|
member |
GuildMember
|
The warned member. |
Example
antiSpam.on("warnAdd", (member) => console.log(`${member.user.tag} has been warned.`));
spamThresholdBan
Emitted when a member reaches the ban threshold.
Parameters:
Name | Type | Description |
---|---|---|
member |
GuildMember
|
The member who reached the ban threshold. |
duplicate |
boolean
|
Whether the member reached the ban threshold by spamming the same message. |
Example
antiSpam.on("spamThresholdBan", (member) => console.log(`${member.user.tag} has reached the ban threshold.`));
spamThresholdKick
Emitted when a member reaches the kick threshold.
Parameters:
Name | Type | Description |
---|---|---|
member |
GuildMember
|
The member who reached the kick threshold. |
duplicate |
boolean
|
Whether the member reached the kick threshold by spamming the same message. |
Example
antiSpam.on("spamThresholdKick", (member) => console.log(`${member.user.tag} has reached the kick threshold.`));
spamThresholdMute
Emitted when a member reaches the mute threshold.
Parameters:
Name | Type | Description |
---|---|---|
member |
GuildMember
|
The member who reached the mute threshold. |
duplicate |
boolean
|
Whether the member reached the mute threshold by spamming the same message. |
Example
antiSpam.on("spamThresholdWarn", (member) => console.log(`${member.user.tag} has reached the warn threshold.`));
spamThresholdWarn
Emitted when a member reaches the warn threshold.
Parameters:
Name | Type | Description |
---|---|---|
member |
GuildMember
|
The member who reached the warn threshold. |
duplicate |
boolean
|
Whether the member reached the warn threshold by spamming the same message. |
Example
antiSpam.on("spamThresholdWarn", (member) => console.log(`${member.user.tag} has reached the warn threshold.`));