New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

niboh

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

niboh

Niboh is a library that provides powerful collectors for Discord Bots made using Discord.js library.

latest
Source
npmnpm
Version
1.0.17
Version published
Maintainers
1
Created
Source

niboh

Niboh is a library that provides powerful collectors for Discord Bots made using Discord.js library.

It allows you to collect almost every type of information, from a ButtonInteraction to a TextInput (message sent in the specified channel)

How to install

yarn add niboh
npm install niboh
pnpm install niboh

Example

Collecting a ButtonInteraction from a message

import { ButtonSelectCollector } from 'niboh'

const messageComponents = [
  new ActionRowBuilder<ButtonBuilder>().setComponents(
    new ButtonBuilder()
      .setCustomId('cool-id')
      .setLabel('Confirm')
      .setButtonStyle(ButtonStyle.Success)
  )
]

const message = await someCoolInteraction.reply({
  fetchReply: true,
  components: messageComponents
})

const buttonSelectCollector = new ButtonSelectCollector({
  location: message.channel,
  target: someCoolInteraction.user
})

const buttonInteraction = await buttonSelectCollector.setProps({ message }).run()

if (buttonInteraction) {
  buttonInteraction.reply({ content: 'Confirmed!' })
}

Make sure to understand that the only part of the library that is actually being used is here

const buttonSelectCollector = new ButtonSelectCollector({
  location: message.channel,
  target: someCoolInteraction.user
})

const buttonInteraction = await buttonSelectCollector.setProps({ message }).run()

if (buttonInteraction) {
  buttonInteraction.reply({ content: 'Confirmed!' })
}

the rest is only a example of message sent with some components to be collected :)

Combined Collectors

You can combine collectors to run at the same time, but how can it be useful? You might want to run a ButtonCollector with a TextInputCollector, for example, imagine you want to ask a user to confirm an operation, so the user can confirm by clicking or writing a specific text.

import { ButtonSelectCollector, TextInputCollector, CombineCollectors } from 'niboh'

const buttonSelectCollector = new ButtonSelectCollector({
  location: message.channel,
  target: someCoolInteraction.user
}).setProps({ message })

const textInputCollector = new TextInputCollector({
  location: message.channel,
  target: someCoolInteraction.user
}).setProps({ pattern: /^confirm$/ })

const combinedCollectors = new CombineCollectors([
  buttonSelectCollector,
  textInputCollector
])

const result = await combinedCollectors.run()

if (result.isButtonSelectInteraction()) {
  const buttonInteraction = result.value
  //   ^ ? = ButtonInteraction | null
}

if (result.isTextInput()) {
  const textInput = result.value
  //   ^ ? = string | null
}

FAQs

Package last updated on 13 Feb 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts