discord.js-rate-limiter
TypeScript icon, indicating that this package has built-in type declarations

1.3.2 • Public • Published

discord.js-Rate-Limiter

NPM Version discord.js Version Downloads

Rate limiter for discord.js.

Installation

npm install discord.js-rate-limiter

Importing

import { RateLimiter } from 'discord.js-rate-limiter';

Example Usage

import { Client, Intents } from 'discord.js';
import { RateLimiter } from 'discord.js-rate-limiter';

let Config = require('../config/config.json');

// Allows 1 command every 2 seconds
let rateLimiter = new RateLimiter(1, 2000);
let client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });

client.on('ready', () => {
    console.log(`Logged in as '${client.user.tag}'!`);
});

client.on('messageCreate', async msg => {
    // Don't respond to bots
    if (msg.author.bot) {
        return;
    }

    if (msg.content === 'test') {
        // Check if user is rate limited
        let limited = rateLimiter.take(msg.author.id);
        if (limited) {
            // Send back a message (or you may want to just drop the request)
            await msg.channel.send(`You're doing that do often, please try again later!`);
            return;
        }

        // Run test command
        await msg.channel.send(`Test command ran!`);
        return;
    }
});

client.login(Config.token);

Example

Package Sidebar

Install

npm i discord.js-rate-limiter

Weekly Downloads

93

Version

1.3.2

License

MIT

Unpacked Size

13.5 kB

Total Files

12

Last publish

Collaborators

  • kevinnovak