Callback System

The callback system aims to be similar to the InteractionHandler but in a more Low Code manner, requiring less coding.

It is important to know that if the bot is restarted, the callback provided in the component may no longer be valid until the component is generated again, so it may not be useful for all situations.

Exemple:

import { ApplicationCommandType } from "discord.js";
import { CreateRow, CreateButton, InteractionHandler} from "ease-discord-js";

export default {
    name: "test",
    description: "command to test the library",
    type: ApplicationCommandType.ChatInput,

    run: async(client, interaction) => {
       return interaction.reply({content: "Hello World!", components: [
            new CreateRow([
                new CreateButton({label: "Primary", style: "Primary", onClick: (client, interaction) => clickHandler(client, interaction)}),
            ])
        ]});
    }
}

const clickHandler = (client, interaction) => {
    interaction.reply({content: "Button Clicked! ( using callback ) ", ephemeral: true});
}

Result:

You can notice that the only change we have in the button is that the callback attribute receives a function. This function will be called when the button is clicked, and we can manipulate the parameters of this function as it is called.

Last updated