npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

client-discord

v1.0.7

Published

Advanced Discord client with useful methods and classes

Downloads

9

Readme

❤ Powerful Discord Client with useful methods

Installation

$ npm install client-discord

Discord.js V13 allowed

Usage

import { Limiter, Client, Util, Discord } from "client-discord"; 
// const  { Limiter, Client, Util, Discord } = require("client-discord");

const client = new Client({token: "BOT_TOKEN", colors: {main: "#00ffff"} }); // creating a discord client, token is required
const prefix = ">";

client.on("ready", () => { // basic ready event
    console.log(`${client.user.tag} is online`) 
})

const cmdLimiter = new Limiter(1, 5000); // creating a new limiter, 1 message per 5 seconds (1sec === 1000 ms)

// Examples
client.on("messageCreate", async (message) => { // message.content = ">example something here"
    const args = message.content.slice(prefix.length).trim().split(/ +/g); // args = ["example", "something", "here"]
    const cmd = args.shift().toLocaleLowerCase(); // cmd = "example" | args = ["something", "here"]
    if (!message.content.toLocaleLowerCase().startsWith(prefix)) return;

    const limitedUser = cmdLimiter.take(message.author.id); // checking an item, returns boolean, true if limited
    if (limitedUser) return message.reply("cooldown");
    
    if (cmd === "timestamp") {
        const embed = client.embed("main").setAuthor({name: "hello"}).setDescription(client.timestamp());
        message.reply({embeds: [embed]})
    }

    if (cmd === "wait") {
        const anyTime = client.wait(Date.now() + 84561645);
        message.reply(`You must wait more ${anyTime.hours} h. ${anyTime.minutes} m. ${anyTime.seconds} s.`);
    }

    if (cmd === "producerange") {
        message.reply(client.produceRange({to: 10}).join(", ")) // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
        message.reply(client.produceRange({from:5, to: 10}).join(", ")) // 5, 6, 7, 8, 9
    }
    
    if (cmd === "uuid") {
        message.reply(client.uuid()) // a48qdb7q6d8u
        // message.reply(client.uuid(undefined, 12)) // a48qdb7q6d8u
    }
});

client.login(); // basic login method

Limiter class from main module

Limiter => DiscordJS Rate Limiter

import { Limiter } from "client-discord";
const limiter1 = new Limiter(4, 15000); // allows 4 uses every 15 seconds

// It can be used for commands cooldown

const limited = limiter1.take("some id");
if (limited) return; // returns true if limited

Additional Client Parameters

Client Class => Client

  • Client.discord => Discord
  • Client.colors => An object with given colors. They can be used with the embed method
  • Client.util => dann-util, useful functions

Additional Methods

wait(date)

Useful for making cooldown.

| PARAMETER | TYPE | OPTIONAL | DEFAULT | ----- |:--------:|:----:|:----:| | date | date | |new Date() |

Returns: object => {

hours: number,
minutes: number,
seconds: number

}

randomItem(array)

Gives a random item from specified array.

| PARAMETER | TYPE | OPTIONAL| DEFAULT | ------------- |:-------------:|:-----:|:----: | array | array | |[] |

Returns: an element

produceRange(Options)

Give an array of numbers in specified range.

Options Object

| PARAMETER | TYPE | OPTIONAL | DEFAULT | ------ |:--------:|:----:|:---:| | to | number | | | from | number | 🗸 | 0 | step | number | 🗸 | 1

Returns: array

// Example
const fromFourToTen = client.produceRange({from: 4, to: 10}) // [4, 5, 6, 7, 8, 9]

timestamp(time, style)

Makes a discord timestamp.

| PARAMETER | TYPE | OPTIONAL | DEFAULT | ------------- |:-------------:|:------:|:----: | time | number | 🗸 | Date.now() | style | TimestampStylesString | 🗸 | f

Returns: string, Discord Timestamp

uuid(type, length)

Generates a unique id.

| PARAMETER | TYPE | OPTIONAL |DEFAULT | ------------- |:-------------:|:---------:|:----: | string | type | 🗸 | mixed | length | number |🗸 | 12

Returns: string

// Example
// Types: number, letters, mixed(not specified)

client.uuid(); // 156asd1qwe1u
client.uuid(null, 6); // as1d5q9r
client.uuid("letters", 8); //  aqjxqwnb
client.uuid("numbers", 16); // 6958941798476178

embed(color)

Changes the format of number ("1,000,000").

| PARAMETER | TYPE | OPTIONAL |DEFAULT | ------------- |:-------------:|:---------:|:----: | color | ColorResolvable or color from ColorObject | 🗸 |

Returns: MessageEmbed

// Example
import { Client} from "client-discord"; // importing Client Class
const client = new Client({token: "BOT_TOKEN", colors: {main: "#00ffff", any: "#edff0f"} }); // creating a client

client.embed() // new MessageEmbed();
client.embed("any") // new MessageEmbed().setColor(client.colors.any); #edff0f
client.embed("#00ff00") // new MessageEmbed().setColor("#00ff00");

Join us!