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.
Install the package
npm install djs-utilityImporting the package
const utility = require("djs-utility");or via import
import * as utility from ("djs-utility");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
paginationEmbedOptionsandemojiOptionsfor defining optional variables. For example:
import { paginationEmbedOptions, emojiOptions, pagination } from "djs-utility";
const emojis: emojiOptions = {
...
}
const options: paginationEmbedOptions = {
...,
emojis
}
pagination(options);Output:
Note: You need some intents to enable these features as per discord.js@v13. For reference see index.ts
const { stringPagination } = require("djs-utility");
stringPagination({
message: message,
pages: [embedOne, embedTwo, ..., lastEmbed]
});Parameters:
- message - The message object (required)
- pages - An array of
Stringas 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
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
stringorMessageEmbed(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
confirmOptionsfor typescript intellisenseFor 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
A code Block Parser to extract language and code out of code blocks.
Parameters:
- string - string containing codeBlock
return:
Array<[Object]>lang ?: stringcode ?: string
Example :
import {codeBlockParser} from "djs-utility";
console.log(
codeBlockParser("```js\n🥳🥳🥳🥳🥳🥳🥳🥳🥳🥳 working```"));Output :
[{ lang: 'js', code: '🥳🥳🥳🥳🥳🥳🥳🥳🥳🥳 working' }]Contributions are always welcome!
- Fork the repo
- Clone the repo
git clone <your forked repo> - Make a new branch for your feature
- Write the code
- Make a new file called
config.jsintestfolder and copy the contents oftest/sample.config.jsand update the token. - Run
npm run test:all(See more scripts inpackage.json) - Push you code and make a pull request
- That's it!
Then you code will be reviewed by the authors.
