Skip to content

ikrishagarwal/djs-utility

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A library to make your discord bot easily.

djs-utility is for helping you out to write less code and do your stuff. It provides you with some pre-written code which you can to do compicated in just cuople of lines.

Documentation

Install the package

npm install djs-utility

Importing the package

const utility = require("djs-utility");

or via import

import * as utility from ("djs-utility");

Using the features

pagination

const { pagination } = require("djs-utility");

pagination({
  message: message,
  pages: [embedOne, embedTwo, ..., lastEmbed],
  initialText: "`!help command` will show an extra help"
});

Parameters:

  • message - The message object (required)
  • pages - An array of MessageEmbeds as individual pages (required)
  • initialPage - The starting page number if you don't want it to be 0. Default is 0 (optional)
  • initialText - If you want any extra text on top of every pages. Default is "" (optional)
  • timeout - The maximun amount of time the reaction collector will listen for reactions. Default is 12000. (optional)
  • emojis - If you don't want the default emojis. Pass an object. (optional)
emojis: {
  pageNumber: EmojiResolvable,
  home: EmojiResolvable,
  left: EmojiResolvable,
  right: EmojiResolvable,
  end: EmojiResolvable,
  stop: EmojiResolvable,
}

You can also import paginationEmbedOptions and emojiOptions for defining optional variables. For example:

import { paginationEmbedOptions, emojiOptions, pagination } from "djs-utility";
const emojis: emojiOptions = {
  ...
}

const options: paginationEmbedOptions = {
  ...,
  emojis
}

pagination(options);

Output:

pagination-example

Note: You need some intents to enable these features as per discord.js@v13. For reference see index.ts


string pagination

const { stringPagination } = require("djs-utility");

stringPagination({
  message: message,
  pages: [embedOne, embedTwo, ..., lastEmbed]
});

Parameters:

  • message - The message object (required)
  • pages - An array of String as individual pages (required)
  • initialPage - The starting page number if you don't want it to be 0. Default is 0 (optional)
  • timeout - The maximun amount of time the reaction collector will listen for reactions. Default is 12000. (optional)
  • emojis - If you don't want the default emojis. Pass an object. (optional)

Emojis are same for this too (emojiOptions)

Similarly you can also import stringPaginationEmbedOptions.

For example:

import { stringPaginationEmbedOptions as pgOptions, stringPagination } from "djs-utility";
const options: pgOptions = {
  ...
}

stringPagination(options);

For NodeJS you can also set alias. For example:

const { stringPagination: pagination } = require("djs-utility");

pagination(...);

Note: You need some intents to enable these features as per discord.js@v13. For reference see index.ts


confirm

const { confirm } = require("djs-utility");

confirm({
  message,
  content: "Are you sure?",
})
  .then((result) => {
    // result is true if user reacts with the check
    // or else it's false if user reacts with cross emoji
  })
  .catch((err) => {
    // err.error = true
    // in the most cases err.errorType will be timeout error
  });

Parameters:

  • message - The message object (required)
  • content - Either it must be a string or MessageEmbed (required)
  • timeout - The maximun amount of time the reaction collector will listen for reactions. Default is 60000. (optional)
  • emojis - If you don't want the default emojis. Pass an object. (optional)
    • check - The check emoji which results to true
    • cross - The cross emoji which results to false

You can import confirmOptions for typescript intellisense

For example:

import { confirm, confirmOptions } from "djs-utility";
const options: confirmOptions = {
  ...
}

confirm(options);

Note: You need some intents to enable these features as per discord.js@v13. For reference see index.ts


codeBlockParser

A code Block Parser to extract language and code out of code blocks.

Parameters:

  • string - string containing codeBlock

return:

  • Array<[Object]>
    • lang ?: string
    • code ?: string

Example :

import {codeBlockParser} from "djs-utility";
console.log(
  codeBlockParser("```js\n🥳🥳🥳🥳🥳🥳🥳🥳🥳🥳 working```"));

Output :

[{ lang: 'js', code: '🥳🥳🥳🥳🥳🥳🥳🥳🥳🥳 working' }]

Contributing

Contributions are always welcome!

Steps to contribute:

  1. Fork the repo
  2. Clone the repo git clone <your forked repo>
  3. Make a new branch for your feature
  4. Write the code
  5. Make a new file called config.js in test folder and copy the contents of test/sample.config.js and update the token.
  6. Run npm run test:all (See more scripts in package.json)
  7. Push you code and make a pull request
  8. That's it!

Then you code will be reviewed by the authors.