@tfagaming/discord.js-docs v1.2.0
@tfagaming/discord.js-docs
A simple parser for the discord.js docs! It uses axios to fetch the data, and it's all Promise-based.
Install
You need to install axios so the package will be able to fetch the data from docs, and then you can install the package with no problems.
npm install @tfagaming/discord.js-docs
yarn add @tfagaming/discord.js-docs
Import
TypeScript:
import { } from '@tfagaming/discord.js-docs';
JavaScript (CommonJS):
const { } = require('@tfagaming/discord.js-docs');
Usage
Create a new parser using the class DocsParser
:
const parser = new DocsParser();
Available discord.js sources in this package:
These are the available source names to use: main
, stable
, rpc
, collection
, builders
, voice
, rest
, next
, core
, proxy
, ws
, util
, and formatters
.
Note: The source
commando
is not available since it's latest version uses discord.js v12, which is deprecated by it's developers.
Fetch everything in a source:
await parser.fetch('main');
Parameter | Type | Required | Description |
---|---|---|---|
source | keyof DiscordJSDocsSources | Yes | The source to fetch. |
Search in a source using query:
await parser.search('main', 'Client');
await parser.search('builders', 'SlashCommand', { rate: 0.5 });
Parameter | Type | Required | Description |
---|---|---|---|
source | keyof DiscordJSDocsSources | Yes | The source to fetch. |
query | string | Yes | The query to find it's best match in the source. |
options? | DocsParserSearchOptions | - | Options of the method. |
Info: The
rate
property in the options must be in this following condition: 0 < rate ≤ 1
Format searched data:
This method is made for Discord bot commands, which simplifies the format of discord.js docs data.
const output = wrapper.format(data);
Parameter | Type | Required | Description |
---|---|---|---|
data | { data: DiscordJSDocsDataTypesStructure, key: string, point: number }[] | Yes | The data to format, usually the data from the method search. |
options? | DocsParserFormatOptions | - | Options of the method. |
Example
Search documentation as a Discord slash command:
The slash command structure:
{
name: 'search',
description: 'Search anything in the discord.js docs!',
type: 1, // <= Chat Input type
options: [{
name: 'query',
description: 'The query to search.',
type: 3, // <= String type
required: true
}]
}
The commands listener:
const parser = new DocsParser();
client.on('interactionCreate', async (interaction) => {
if (!interaction.isChatInputCommand()) return;
if (interaction.commandName === 'search') {
const query = interaction.options.getString('query', true);
await interaction.deferReply();
const searched = await parser.search('main', query, {
rate: 0.5,
include: ['classes', 'functions', 'typedefs']
});
if (searched.length <= 0) {
await interaction.followUp({
content: 'Nothing was found.'
});
return;
};
const formatted = parser.format(searched);
const final = formatted.map((v) => `${v.emoji} [${v.name}](${v.url})`);
await interaction.followUp({
embeds: [
new EmbedBuilder()
.setDescription(`${final.join('\n')}`)
]
});
return;
};
});
Result after using the command:
License
GPL v3, General Public License version 3.0.