Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/Redstoneguy129/Deno-Discord-Slash-Commands

Deno Slash Commands for Discord
https://github.com/Redstoneguy129/Deno-Discord-Slash-Commands

Last synced: about 2 months ago
JSON representation

Deno Slash Commands for Discord

Awesome Lists containing this project

README

        

# Deno Discord Slash Commands

This package provides Slash command support for the new Discord Interactions API.

![](https://img.shields.io/github/v/release/Redstoneguy129/Deno-Discord-Slash-Commands?label=Version&style=for-the-badge)
![](https://forthebadge.com/images/badges/made-with-typescript.svg)
![](https://img.shields.io/github/license/Redstoneguy129/Deno-Discord-Slash-Commands?style=for-the-badge)
![](https://img.shields.io/github/issues/Redstoneguy129/Deno-Discord-Slash-Commands?style=for-the-badge)

We've documented every type used by the interactions API, so you can make use of this library in your own projects, or make use of the utility functions we've provided to create, get, and delete slash commands.

## Installation

This is a [Deno](https://deno.land/) module available from the [Deno module registry](https://deno.land/x/discord_slash_commands).

## Importing

To import:

```ts
import { DiscordInteractions } from "https://deno.land/x/discord_slash_commands@version/mod.ts";
```

## Initialization

```js
const interaction = new DiscordInteractions({
applicationId: "1234567890",
authToken: "bot token",
publicKey: "discord-provided public key",
});
```

## Usage

> The following examples use `496279654483886100` as a guild id and `545581357812678656` as a command id

### Getting Commands

```js
// Get Global Commands
await interaction
.getApplicationCommands()
.then(console.log)
.catch(console.error);

// Get Guild Commands
await interaction
.getApplicationCommands("496279654483886100")
.then(console.log)
.catch(console.error);
```

### Creating Commands

```js
const command = {
name: "avatar",
description: "get a users avatar",
options: [
{
name: "big",
description: "should the image be big",
type: ApplicationCommandOptionType.BOOLEAN,
},
],
};

// Create Global Command
await interaction
.createApplicationCommand(command)
.then(console.log)
.catch(console.error);

// Create Guild Command
await interaction
.createApplicationCommand(command, "496279654483886100")
.then(console.log)
.catch(console.error);
```

### Editing Commands

```js
const command = {
name: "avatar",
description: "get a users avatar",
options: [
{
name: "small",
description: "should the image be small",
type: ApplicationCommandOptionType.BOOLEAN,
},
],
};

// Edit Global Command
await interaction
.createApplicationCommand(command, null, "545581357812678656")
.then(console.log)
.catch(console.error);

// Edit Guild Command
await interaction
.createApplicationCommand(command, "496279654483886100", "545581357812678656")
.then(console.log)
.catch(console.error);
```

### Deleting Commands

```js
// Delete Global Command
await interaction
.deleteApplicationCommand("545581357812678656")
.then(console.log)
.catch(console.error);

// Delete Guild Command
await interaction
.deleteApplicationCommand("545581357812678656", "496279654483886100")
.then(console.log)
.catch(console.error);
```

## Contributing

Help is much-needed to improve the library and add all features. Please feel free to make a PR to [the repository](https://github.com/Redstoneguy129/Deno-Discord-Slash-Commands).

This is a port of [MeguminSama's NodeJS Repo](https://github.com/MeguminSama/discord-slash-commands/) to Deno.