# dceasybuttons

> 😎 Discord buttons with easy callback system (onClick)

Latest version **0.1.4** (published 2021-06-01) · GNU GPL v3 license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install dceasybuttons
pnpm add dceasybuttons
yarn add dceasybuttons
bun add dceasybuttons
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.1.4 |
| Published | 2021-06-01 |
| First published | 2021-05-30 |
| Weekly downloads | 0 |
| License | GNU GPL v3 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 12.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Kıraç Armağan Önal |
| Maintainers | armagan_ |
| Keywords | discord, dc, buttons, easy, fast, callback, click, onclick, discordbuttons, armagan, thearmagan |

## Links

- npm: https://www.npmjs.com/package/dceasybuttons
- Repository: https://github.com/TheArmagan/dceasybuttons
- Homepage: https://github.com/TheArmagan/dceasybuttons#readme
- Issues: https://github.com/TheArmagan/dceasybuttons/issues
- npm.io page: https://npm.io/package/dceasybuttons

## Dependencies (2)

- [discord.js](https://npm.io/package/discord.js.md) ^12.5.3
- [discord-buttons](https://npm.io/package/discord-buttons.md) ^3.0.1

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 0.1.4 (latest) — 2021-06-01
- 0.1.3 — 2021-06-01
- 0.1.2 — 2021-05-30
- 0.1.1 — 2021-05-30
- 0.1.0 — 2021-05-30

## README

> # Discord Easy Buttons
> 😎 Discord buttons with easy callback system (onClick)

## Example
```js
const { Client } = require("discord.js");
const { MessageActionRow } = require("discord-buttons");
const client = new Client();
const easyButtons = require("dceasybuttons");

// Only for one time while starting the entire project
easyButtons.attachToClient(client);

client.on("message", async (message) => {
  
  let args = message.content.split(" ");

  if (args[0] == `abc!testeasybuttons`) {

    const myButton = easyButtons.createButton(
      {
        // These are discord-button data.
        label: "Cool Button",
        style: "gray", // "blurple" or "gray" or "green" or "red"
        disabled: false,

        // With defer option button never gives 
        // "This interaction failed" message while
        // bot online.
        defer: true,
        // After 10 seconds of not clicking to buttons,
        // button automatically get disposed. For saving
        // memory.
        timeout: 10000
      }
    );

    
    // Creating a message text for later use.
    let msgText = "Click button to change button name to your name. (Button automatically gets disabled after 10 seconds of inactivity.)";
    
    // Creating a message with myButton.
    let msg = await message.channel.send(msgText, myButton);

    // Creating callback using onClick function
    // for updating button label with new clicker's
    // tag.
    myButton.callback.onClick((event) => {
      // Set muButton's new label to clicker's tag.
      myButton.label = event.clicker.user.tag;
      // And update message with new buttons.
      msg.edit(msgText, myButton)
    });

    // On timeout disable buttons.
    myButton.callback.onTimeout(() => {
      // Disable the myButton, soo people 
      // can't click it anymore.
      myButton.disabled = true;
      // And update message with new buttons.
      msg.edit(`${msgText} (Ended)`, myButton)
    });

    // Available callbacks: onClick(event, buttonCallback), onTimeout(buttonCallback), onDispose()
    
  }

});

client.login("<your token>");
```

## Another example
```js
const { Client } = require("discord.js");
const { MessageButton } = require("discord-buttons");
const client = new Client();
const easyButtons = require("dceasybuttons");
const { ButtonCallback } = require("dceasybuttons");

// Only for one time while starting the entire project
easyButtons.attachToClient(client);

client.on("message", async (message) => {

  let args = message.content.split(" ");

  if (args[0] == `abc!countup`) {

    // Create a ButtonCallback with 10s timeout.
    let myButtonCallback = new ButtonCallback({timeout: 10000});
    // Create a new button
    let myButton = new MessageButton()
      .setStyle("red")
      .setLabel("0")
      // And set id to button callback
      .setID(myButtonCallback.id);
    
    let number = 0;

    // Same stuff again.
    myButtonCallback.onClick((event) => {
      event.defer();
      myButton.setLabel(`${++number}`)
      event.message.edit("Count Up +1", myButton);
    });
    
    message.channel.send("Count Up +1", myButton);
  }

});

client.login("<token>")
```

## Updates
### 0.1.4
- Default timeout to 60 seconds
- New example added.
### 0.1.3
- Now supports latest version of `discord-buttons`

Created by [Kıraç Armağan Önal](http://thearmagan.github.io)

---
_Source: https://npm.io/package/dceasybuttons · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
