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.
banThreshold: 7, // Amount of messages sent in a row that will cause a ban.
maxInterval: 2000, // Amount of time (in ms) in which messages are cosidered spam.
warnMessage: "{@user}, Please stop spamming.", // Message will be sent in chat upon warning.
banMessage: "**{user_tag}** has been banned for spamming.", // Message will be sent in chat upon banning.
maxDuplicatesWarning: 7, // Amount of same messages sent that will be considered as duplicates that will cause a warning.
maxDuplicatesBan: 15, // Amount of same messages sent that will be considered as duplicates that will cause a ban.
deleteMessagesAfterBanForPastDays: 1, // Amount of days in which old messages will be deleted. (1-7)
exemptPermissions: ["MANAGE_MESSAGES", "ADMINISTRATOR", "MANAGE_GUILD", "BAN_MEMBERS"], // Bypass users with at least one of these permissions
ignoreBots: true, // Ignore bot messages.
verbose: false, // Extended Logs from module.
ignoredUsers: [], // Array of string user IDs that are ignored.
ignoredRoles: [], // Array of string role IDs or role name that are ignored.
ignoredGuilds: [], // Array of string Guild IDs that are ignored.
ignoredChannels: [] // Array of string channels IDs that are ignored.
});
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) resetData() → {AntiSpamData}
Resets the cache data of the Anti Spam instance.
Example
const data = antiSpam.resetData();
console.log(`Cleared a total of ${data.messageCache.length} cached messages.`);
Events
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.`));
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' |
Example
antiSpam.on("error", (message, error, type) => {
console.log(`${message.author.tag} couldn't receive the sanction '${type}', error: ${error}`);
});
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.`));
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.`));
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.`));
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.`));