Discord.https - v3.0.16
    Preparing search index...

    Class default

    Discord HTTPS Interaction Client.

    Handles registration of commands, buttons, modals, select menus, context menus, and autocomplete interactions with their associated middleware.

    Also exposes a REST client for direct API calls.

    import Client, { InteractionResponseType } from "./Client.js";
    import NodeAdapter from "@discordhttps/nodejs-adapter";

    const client = new Client({
    token: process.env.BOT_TOKEN!,
    publicKey: process.env.PUBLIC_KEY!,
    httpAdapter: new NodeAdapter(),
    });

    client.command(
    (builder) => builder.setName("ping").setDescription("Replies with Pong!"),
    async (interaction, client, _, res) => {
    res.writeHead(200, {
    "Content-Type": "application/json",
    });
    const username = interaction.user
    ? interaction.user.global_name
    : interaction.member.user.global_name;
    res.end(
    JSON.stringify({
    type: InteractionResponseType.ChannelMessageWithSource,
    data: {
    content: `Hello! ${username}`,
    },
    })
    );
    }
    );

    await client.listen("interactions", 3000, () => {
    console.log(
    "Listening for interactions on port 3000 at the /interactions endpoint"
    );
    });

    Hierarchy

    • HttpInteractionServer
      • default
    Index

    Constructors

    Properties

    isDebug: boolean = false
    rest: REST

    REST API client instance used for interacting with Discord's HTTP API.

    Methods

    • Registers an autocomplete interaction with its associated middleware.

      Parameters

      Returns void

      const weather = router.command(
      async(builder) =>
      builder
      .setName("weather")
      .setDescription("Query weather information!")
      .addStringOption(option =>
      option
      .setName("city") // Option Name
      .setDescription("City to get the weather for")
      .setAutocomplete(true) // Enable autocomplete for this option
      ),
      handler
      );
      router.autocomplete(weather.getAutoCompleteKey("city"), autocompleteMiddleware);
    • Registers a button interaction with its associated middleware.

      Parameters

      Returns void

      router.button("custom_button_id", async (interaction) => await interaction.reply("Button Pressed!"));
      
    • Prints debug messages with a timestamp if debug mode is enabled.

      Parameters

      • ...message: string[]

        Message parts to log.

      Returns void

    • Returns helpers for registering slash commands.

      Parameters

      • log: boolean = true

        Log progress. Defaults to true.

      Returns Promise<
          {
              payload: APIApplication;
              globalSlashRegistar(): Promise<void>;
              localSlashRegistar(guildId: string): Promise<void>;
          },
      >

      An object containing:

      • globalSlashRegistrar: Function to register commands globally.
      • localSlashRegistrar(guildId: string): Function to register commands locally for a specific guild, requires the guild ID as a parameter.
      • payload: The payload returned from GET /applications/@me.
    • Starts listening for HTTP requests using the configured HttpAdapter.

      Parameters

      • endpoint: string

        The endpoint path (e.g. "/interactions").

      • ...args: any

        Extra arguments passed to the adapter's listen method. Adapter-specific usage: - Node.js Adapter: standard Node.js server arguments, e.g., port and optional callback: ts client.listen("/interactions", 3000, () => { console.log("Server is active at /interactions"); }); - Cloudflare Adapter: expects a Request object from the Cloudflare Worker fetch event: ts return await client.listen("/interactions", request);

      Returns Promise<any>

      A promise resolving to the adapter's listen result.

    • Registers a mentionable select interaction with its associated middleware.

      Parameters

      Returns void

      router.mentionableSelect("mentionableSelectName", mentionableSelectMiddleware);