1.2.0 • Published 10 months ago

@tfagaming/discord.js-docs v1.2.0

Weekly downloads
-
License
GPL-3.0
Repository
-
Last release
10 months ago

@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');
ParameterTypeRequiredDescription
sourcekeyof DiscordJSDocsSourcesYesThe source to fetch.

Search in a source using query:

await parser.search('main', 'Client');

await parser.search('builders', 'SlashCommand', { rate: 0.5 });
ParameterTypeRequiredDescription
sourcekeyof DiscordJSDocsSourcesYesThe source to fetch.
querystringYesThe 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);
ParameterTypeRequiredDescription
data{ data: DiscordJSDocsDataTypesStructure, key: string, point: number }[]YesThe 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.

1.2.0

10 months ago

1.1.1

10 months ago

1.1.0

10 months ago

1.0.0

10 months ago

0.1.2

10 months ago

0.1.1

10 months ago

0.1.0

10 months ago