1.0.7 • Published 2 years ago

client-discord v1.0.7

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

❤ 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.

PARAMETERTYPEOPTIONALDEFAULT
datedatenew Date()

Returns: object => {

hours: number,
minutes: number,
seconds: number

}

randomItem(array)

Gives a random item from specified array.

PARAMETERTYPEOPTIONALDEFAULT
arrayarray[]

Returns: an element

produceRange(Options)

Give an array of numbers in specified range.

Options Object

PARAMETERTYPEOPTIONALDEFAULT
tonumber
fromnumber🗸0
stepnumber🗸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.

PARAMETERTYPEOPTIONALDEFAULT
timenumber🗸Date.now()
styleTimestampStylesString🗸f

Returns: string, Discord Timestamp

uuid(type, length)

Generates a unique id.

PARAMETERTYPEOPTIONALDEFAULT
stringtype🗸mixed
lengthnumber🗸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").

PARAMETERTYPEOPTIONALDEFAULT
colorColorResolvable 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!

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago