# autocode-discord-interaction

> This npm makes it easy to use the discord interactions inside autocode.

Latest version **1.2.0** (published 2022-09-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install autocode-discord-interaction
pnpm add autocode-discord-interaction
yarn add autocode-discord-interaction
bun add autocode-discord-interaction
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2022-09-29 |
| First published | 2021-12-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 17.5 KB |
| Known vulnerabilities | 0 (+23 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Meiraba |
| Maintainers | meiraba |
| Keywords | discord, autocode, interaction |

## Links

- npm: https://www.npmjs.com/package/autocode-discord-interaction
- Repository: https://github.com/LMeiraba/autocode-discord-interaction
- Homepage: https://github.com/LMeiraba/autocode-discord-interaction#readme
- Issues: https://github.com/LMeiraba/autocode-discord-interaction/issues
- npm.io page: https://npm.io/package/autocode-discord-interaction

## Dependencies (2)

- [axios](https://npm.io/package/axios.md) ^0.27.2
- [form-data](https://npm.io/package/form-data.md) ^4.0.0

## Recent versions

- 1.2.0 (latest) — 2022-09-29
- 1.1.0 — 2022-03-04
- 1.0.1 — 2022-02-09
- 1.0.0 — 2022-02-09
- 0.0.6 — 2022-01-11
- 0.0.5 — 2021-12-24
- 0.0.4 — 2021-12-24
- 0.0.3 — 2021-12-23
- 0.0.2 — 2021-12-13
- 0.0.1 — 2021-12-12

## README

# Autocode Discord Interaction

This npm makes it easy to use discord interactions inside autocode.

# Change log

### v-1.2.0

1. Improved file uploading.
2. Overall code revamped.

### v-1.1.0

Improved returned response schemes.

### v-1.0.0

Added support for modal interaction.
[example](https://www.npmjs.com/package/autocode-discord-interaction#example-uses)

### v-0.0.6
A small bug fixed.

### v-0.0.5
Forgot to add `form-data` package inside the npm so error go brrrr.... 🤦‍♂️🤦‍♂️🤦‍♂️🤦‍♂️🤦‍♂️🤦‍♂️

### v-0.0.4
Fixed a small bug where it will give error when `attachments` params is not provided. 😅🤦‍♂️

### v-0.0.3
1. Added support for uploading files.
2. Improved readme :)

# Available APIs

1. Callback

| API types | Description |
| ----------- | ----------- |
| command_reply | Reply to any application command. Eg: slash command |
| command_defer | Reply with a thinking message to any application command that can be edited later. |
| component_defer | Acknowledge a message component that can be edited later. Eg: buttons |
| component_update | Update the message where the component was present. |
| autocomplete | Return some choices to the user. |
| form_modal | Reply with a popup form. |


2. Followup

| API types | Description |
| ----------- | ----------- |
| edit_original | Edit the original message created for the interaction. |
| get_original | Get info about the original message created for the interaction. |
| delete_original | Delete the original message created for the interaction. |
| create | Create a new followup message for an interaction. (can only be used if the interaction was already replied by any of the callback apis) |
| get | Get info about any newly created followup message. |
| edit | Edit any followup message |
| delete | Delete any followup message |

**Note:** Some of the apis for followup are not fully tested, so if you find any bugs please report it.

# Example uses

### Modal interaction
```js
await interaction.callback.form_modal(event, {
    custom_id: `form_1`,
    title: 'This is an example form',
    text_inputs: [
      {
        style: 'short',
        custom_id: 'name',
        label: `What's your name?`,
        placeholder: `write your name here`, // optional
        required: true, // optional
        //value: 'some default value',
        //max_length: 100,
        min_length: 1, // optional
      },
      {
        style: 'long', 
        custom_id: 'description',
        label: `Describe yourself.`,
        placeholder: `Some text here`, // optional
        required: true, // optional
        //value: 'some default value',
        //max_length: 100,
        min_length: 1, // optional
      },
    ]
  })
```
![modal interaction](https://i.imgur.com/RGIjAEH.png)

You can upto 5 text inputs

### Uploading files/attachments
```js
const interaction = require('autocode-discord-interaction')

await interaction.callback.command_reply(context.params.event,{
    content: 'file',
    attachments: [
      {
        name: 'file.txt', //any file name with extension
        buffer: Buffer.from('hello'), //any buffer under 8 mb, could be more if the server is boosted
        description: 'some text' //any string, this params is optional
      }
    ]
})
```
You can upload upto 10 file in one message.

### Reply any application command with a normal message
```js
const interaction = require('autocode-discord-interaction')

await interaction.callback.command_reply(context.params.event,{
    content: 'hello!'
})
```
![normal reply](https://i.imgur.com/u5R7s5g.png)

### Reply any application command with an ephemeral message
```js
const interaction = require('autocode-discord-interaction')

await interaction.callback.command_reply(context.params.event,{
    content: 'hello!'
},{ephemeral: true})
```
![ephemeral reply](https://i.imgur.com/XxsCtJE.png)

### Reply any application command with a thinking message/defer message
```js
const interaction = require('autocode-discord-interaction')

await interaction.callback.command_defer(context.params.event)
```
![defer message](https://i.imgur.com/nnBCH75.png)

Ephemeral thinking message also works.

![ephemeral defer message](https://i.imgur.com/JLj93Sk.png)

## For more details check out my [app](https://autocode.com/app/meiraba/interaction/) in autocode.

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