Plume API

Using the NPM package

How to use Plume API using the official NPM package.

To make it easier to use our API, we have created an official NPM package for JavaScript and TypeScript. Here is a quick tutorial on how to use it.

Installing the package

To install the package, run this command in your project:

npm i @sodiumlabs/plume-api@latest

Using the package

The documentation of the package is available here.

example.js
const { PlumeAPI } = require("@sodiumlabs/plume-api");

// create a PlumeAPI class instance
const plumeAPI = new PlumeAPI();

// fetch the /api/math endpoint
const data = await plumeAPI.math("100*sqrt(15^30)/sin(10PI)");

// log the data
console.log(data);
// {
//     "result": "-3.575674967555855e+34"
// }
example.js
import { PlumeAPI } from "@sodiumlabs/plume-api";

// create a PlumeAPI class instance
const plumeAPI = new PlumeAPI();

// fetch the /api/math endpoint
const data = await plumeAPI.math("100*sqrt(15^30)/sin(10PI)");

// log the data
console.log(data);
// {
//     "result": "-3.575674967555855e+34"
// }

Using discord.js

If you are using discord.js, it is recommended to add Plume API directly on your client, so you can use it anywhere in your project.

index.js
const { Client } = require("discord.js");
const { PlumeAPI } = require("@sodiumlabs/plume-api"); 

// Your discord.js client
const client = new Client({
    /* ... */
});

// Attach PlumeAPI to your client
client.plumeAPI = new PlumeAPI(); 

You can now use Plume API anywhere in your bot. For example, if you followed the guide you can use the API in a slash command like that:

commands/fun/joke.js
async execute(interaction) {
    const client = interaction.client;

    // Get a random joke
    const joke = await client.plumeAPI.joke(); 

    // Show the response
    await interaction.reply(
        `Question: ${joke.question}`
        + `\nAnswer: ||${joke.answer}||`
    );
}

Images endpoints

To send an image received from the API, you can use the AttachmentBuilder class from discord.js:

commands/fun/facts.js
const { AttachmentBuilder } = require("discord.js"); 

async execute(interaction) {
    const client = interaction.client;

    // Since downloading the image can take some time
    // depending on your connection speed, you should defer.
    await interaction.deferReply(); 

    const buffer = await client.plumeAPI.facts("PlumeAPI is cool!"); // this returns an image (buffer)
    const attachment = new AttachmentBuilder(buffer, { name: "image.png" }); 

    await interaction.editReply({ files: [attachment] }); 
}

On this page