npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

rescript-discordjs

v0.3.0

Published

<div align="center"> <br /> <p> <a href="https://discord.js.org"><img src="https://discord.js.org/static/logo.svg" width="546" alt="discord.js" /></a> </p> <br /> <p> <a href="https://www.npmjs.com/package/rescript-discordjs"><img src="https:/

Readme

About

rescript-discordjs are Rescript bindings for discord.js

discord.js is a powerful Node.js module that allows you to easily interact with the Discord API.

  • Object-oriented
  • Predictable abstractions
  • Performant
  • 100% coverage of the Discord API

Installation

Node.js 16.9.0 or newer is required.

npm install rescript-discord
yarn add rescript-discord
pnpm add rescript-discord

Example usage

Install rescript-discordjs and discord.js:

npm install rescript-discord discord.js @discordjs/rest discord-api-types/v9
yarn add rescript-discord discord.js discord.js @discordjs/rest discord-api-types/v9
pnpm add rescript-discord discord.js discord.js @discordjs/rest discord-api-types/v9

Add rescript-discord on bsconfig.json and open in global scope

{
  ...
  "bs-dependencies": [
    "rescript-discordjs",
  ],
  "bsc-flags": ["-open Discord"]
}

Register a slash command against the Discord API:

module Rest = {
  type t
  @module("@discordjs/rest") @new external make: {"version": int} => t = "REST"
  @send external setToken: (t, string) => t = "setToken"
  @send
  external put: (t, string, {"body": array<SlashCommandBuilder.json>}) => Js.Promise.t<unit> = "put"
  @send
  external delete: (t, string) => Js.Promise.t<unit> = "delete"
}

module Routes = {
  type t
  @module("discord-api-types/v9") @scope("Routes")
  external applicationCommands: (~clientId: string) => string = "applicationCommands"
  @module("discord-api-types/v9") @scope("Routes")
  external applicationCommand: (~clientId: string, ~commandId: string) => string =
    "applicationCommand"
}
module ExampleCommand = {
  let data =
    SlashCommandBuilder.make()
    ->SlashCommandBuilder.setName("example")
    ->SlashCommandBuilder.setDescription("Example Command")

  let execute = async (interaction) => {
    switch await interaction->Interaction.reply(
      ~options={"content": "Ping!"},
      (),
    ) {
    | exception JsError(obj) =>
      JsError(obj)->raise
    | _ => ()
    }
  }
}


let exampleCommand = ExampleCommand.data->SlashCommandBuilder.toJSON

let commands = [exampleCommand]

let token = "{Discord Bot Token}"
let clientId = "{Discord Client Id}"



Rest.make({"version": 9})
->Rest.setToken(token)
->Rest.put(Routes.applicationCommands(~clientId), {"body": commands})
->thenResolve(() => Js.log("Successfully registered application commands."))
->catch(e => {
  switch e {
  | JsError(obj) =>
    switch Js.Exn.message(obj) {
    | Some(msg) => Js.Console.error("Deploy Commands Error: " ++ msg)
    | None => Js.Console.error("Must be some non-error value")
    }
  | _ => Js.Console.error("Some unknown error")
  }
  resolve()
})
->ignore

Afterwards we can create a quite simple example bot:


let onInteraction = async (interaction: Interaction.t) => {

  let isCommand = interaction->Interaction.isCommand
  let isButton = interaction->Interaction.isButton
  switch (isCommand, isButton) {
  | (true, false) => {
      let commandName = interaction->Interaction.getCommandName
      let command = commands->Collection.get(commandName)->Js.Nullable.toOption
      switch command {
      | None => Js.Console.error("Bot.res: Command not found")
      | Some(module(Command)) =>
        switch await Command.execute(interaction) {
        | exception e =>
          switch e {
          | JsError(obj) => Js.Console.error(obj)
          | _ => Js.Console.error(e)
          }
        | _ =>
          Js.log(
            `Successfully served the command ${commandName}`,
          )
        }
      }
    }

  | (false, true) => {
      let buttonCustomId = interaction->Interaction.getCustomId
      let button = buttons->Collection.get(buttonCustomId)->Js.Nullable.toOption

      switch button {
      | None => Js.Console.error("Bot.res: Button not found")
      | Some(module(Button)) =>
        switch await Button.execute(interaction) {
        | exception e =>
          switch e {
          | JsError(obj) => Js.Console.error(obj)
          | _ => Js.Console.error(e)
          }
        | _ =>
          Js.Console.log(
            `Successfully served button press "${buttonCustomId}"`,
          )
        }
      }
    }
  | (_, _) => Js.Console.error("Bot.res: Unknown interaction")
  }
}

client->Client.on(
  #ready(
    () => {
      Js.log("Logged In")
    },
  ),
)

client->Client.on(#interactionCreate(interaction => interaction->onInteraction->ignore))

client->Client.login(token)->ignore

Contributing

Most of these bindings are incomplete. If you need something not provided, write a binding for it!