Skip to content

Commit

Permalink
Merge pull request #17 from Romejanic/next
Browse files Browse the repository at this point in the history
Release 1.0.0
  • Loading branch information
Romejanic authored Apr 4, 2023
2 parents 3d37676 + 9767d84 commit 4093fc4
Show file tree
Hide file tree
Showing 25 changed files with 976 additions and 743 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
node-version: [16.x, 17.x, 18.x, 19.x]

steps:
- uses: actions/checkout@v3
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Publish Slasher

on:
release:
types: [created]
types: [published]

jobs:
build:
Expand All @@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
- run: npm ci
- run: npm run build

Expand All @@ -22,7 +22,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm run build
Expand Down
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ Forget about `SlashCommandBuilder` and `REST`. Slasher takes care of all of it f

Even if you're not using discord.js to build your bot, you can still make use of the handy CLI tool to make adding slash commands painless!

### Slasher currently supports discord.js v14 ONLY. The package will no longer work with v13.

## Guides
**If you are using Slasher for the first time, please see the [Getting Started](./docs/guides/getting-started.md) guide.**

**If you are migrating an existing bot, please see the [Slasher Migration](./docs/guides/upgrading-to-slasher.md) guide.**

## Install
Install for use in a node project
```sh
Expand All @@ -45,20 +52,21 @@ First we create our `commands.json` definition file:
```
Then run the `slasher` utility and follow the prompts to upload it to Discord!
```sh
$ slasher
$ npx slasher
```
Then we can create our bot!
```js
const { SlasherClient } = require("discord.js-slasher");
// import { SlasherClient } from 'discord.js-slasher';
const { Events } = require("discord.js");
const { SlasherClient, SlasherEvents } = require("discord.js-slasher");
// alternatively use import statements

const client = new SlasherClient({ useAuth: true });
const client = new SlasherClient();

client.on("ready", () => {
client.on(Events.ClientReady, () => {
console.log("Logged in as " + client.user.tag);
});

client.on("command", (ctx) => {
client.on(SlasherEvents.CommandCreate, (ctx) => {
ctx.reply(`Howdy ${ctx.user.tag}!`);
});

Expand Down
8 changes: 7 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
# Slasher Documentation
Welcome to the official documentation page for Slasher!

If you are upgrading from an older version of Slasher, see **Upgrade Guides** below.

## Guides
- [Getting started](./guides/getting-started.md)
- [command.json format](./guides/command-json.md)
- [Adding options](./guides/adding-options.md)
- [Handling modals](./guides/handling-modals.md)

## Upgrade Guides
- [Upgrading an existing bot to Slasher](./guides/upgrading-to-slasher.md)
- [Upgrading to 1.0.0 and discord.js v14](./guides/djs-14-upgrade.md)

## API Reference
|Type|Description|
|----|-----------|
|[SlasherClient](./api/SlasherClient.md)|The client for using Slasher with discord.js|
|[SlasherClientOptions](./api/SlasherClientOptions.md)|The options class for creating the bot client|
|[SlasherEvents](./api/SlasherEvents.md)|Enum of events fired by the Slasher client|
|[CommandContext](./api/CommandContext.md)|The context object passed by the `command` event|
|[Command](./api/Command.md)|Alias type for [CommandInteraction](https://discord.js.org/#/docs/main/stable/class/CommandInteraction)|
|[CommandOptions](./api/CommandOptions.md)|Class for accessing the options set by the user.|
15 changes: 0 additions & 15 deletions docs/api/Command.md

This file was deleted.

34 changes: 17 additions & 17 deletions docs/api/CommandContext.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# CommandContext
`CommandContext` is an object which is passed as a parameter to the [command](./SlasherClient.md#command) event of [SlasherClient](./SlasherClient.md). It provides useful context about the command currently being executed and the user who sent it. It also provides details about the current server when being used within one.
`CommandContext` is an object which is passed as a parameter to the [CommandCreate](./SlasherClient.md#command) event of [SlasherClient](./SlasherClient.md). It provides useful context about the command currently being executed and the user who sent it. It also provides details about the current server when being used within one.

**Table of Contents**
1. [Import (types only)](#import-types-only)
Expand All @@ -23,11 +23,11 @@ import { CommandContext } from 'discord.js-slasher';
|Name|Type|Optional|Description|
|----|----|--------|-----------|
|name|string|no|The name of the executed command|
|command|[Command](./Command.md)|no|The full command interaction object|
|command|[ChatInputCommandInteraction](https://discord.js.org/#/docs/discord.js/main/class/ChatInputCommandInteraction)|no|The full command interaction object|
|options|[CommandInteractionOptionResolver](https://discord.js.org/#/docs/main/stable/class/CommandInteractionOptionResolver)|no|The options passed into the command by the user|
|isServer|boolean|no|Is the current message in a server text channel?|
|isDM|boolean|no|Is the current message in the user's direct message channel?|
|?channel|[TextBasedChannels](https://discord.js.org/#/docs/main/stable/typedef/TextBasedChannels)|yes|The channel which the command was run in|
|?channel|[TextBasedChannel](https://discord.js.org/#/docs/main/stable/typedef/TextBasedChannels)|yes|The channel which the command was run in|
|user|[User](https://discord.js.org/#/docs/main/stable/class/User)|no|The user who sent the command|
|?server|object (see below)|yes|Server specific values. This object will be undefined if `isServer` is false, so ensure you check that you're in a server before using this object.|
|client|[SlasherClient](./SlasherClient.md)|no|The bot's client object|
Expand All @@ -40,8 +40,8 @@ import { CommandContext } from 'discord.js-slasher';
|guild|[Guild](https://discord.js.org/#/docs/main/stable/class/Guild)|The server's guild object, which allows access to all properties|
|member|[GuildMember](https://discord.js.org/#/docs/main/stable/class/GuildMember)|The user's member object, for accessing roles and permissions|
|owner|boolean|Whether the user is the owner of the server|
|isUserAdmin|boolean|Whether the user has the `ADMINISTRATOR` permission on this server|
|channelPermissions|[Permissions](https://discord.js.org/#/docs/main/stable/class/Permissions) (readonly)|The user's permissions in the channel which the message was sent in|
|isUserAdmin|boolean|Whether the user has the `Administrator` permission on this server|
|channelPermissions|[PermissionsBitField](https://discord.js.org/#/docs/discord.js/main/class/PermissionsBitField) (readonly)|The user's permissions in the channel which the message was sent in|



Expand All @@ -52,18 +52,18 @@ Replies to the command interaction with a certain message. This will mark the in

|Parameter|Type |Description|Required|
|---------|-------------------------------------|-----------|------|
|content|string or [MessageEmbed](https://discord.js.org/#/docs/main/stable/class/MessageEmbed) or [InteractionReplyOptions](https://discord.js.org/#/docs/main/stable/typedef/InteractionReplyOptions)|What to reply to the message with.|yes|
|hidden|boolean|Whether this message will be visible only to the sender|no (default `false`)|
|content|string or [EmbedBuilder](https://discord.js.org/#/docs/discord.js/main/class/EmbedBuilder) or [InteractionReplyOptions](https://discord.js.org/#/docs/main/stable/typedef/InteractionReplyOptions)|What to reply to the message with.|yes|
|hidden|boolean|Whether this message will be visible only to the sender [(ephemeral repsonse)](https://discordjs.guide/slash-commands/response-methods.html#ephemeral-responses)|no (default `false`)|

**Returns:** `Promise<`[Message](https://discord.js.org/#/docs/main/stable/class/Message)` | void>`
**Returns:** `Promise<`[Message](https://discord.js.org/#/docs/main/stable/class/Message)` | `[InteractionResponse](https://discord.js.org/#/docs/discord.js/main/class/InteractionResponse)`>`
A promise for the sent reply message

### .defer(?hidden)
Marks that the response to the message will be deferred (i.e. delayed until later). This will be useful if you need to perform some kind of calculation/fetching before a response can be shown. This should always be done **first** if you know you'll need to defer the response.

e.g.
```js
client.on("command", async (ctx) => {
client.on(SlasherEvents.CommandCreate, async (ctx) => {
await ctx.defer(); // defer the response

// perform calculations
Expand All @@ -76,9 +76,9 @@ In Discord, deferring the response will display `"<botname> is thinking..."` unt

|Parameter|Type |Description|Required|
|---------|-------------------------------------|-----------|------|
|hidden|boolean|Whether this message will be visible only to the sender|no (default `false`)|
|hidden|boolean|Whether this message will be visible only to the sender [(ephemeral repsonse)](https://discordjs.guide/slash-commands/response-methods.html#ephemeral-responses)|no (default `false`)|

**Returns:** `Promise<void>`
**Returns:** `Promise<`[InteractionResponse](https://discord.js.org/#/docs/discord.js/main/class/InteractionResponse)`>`
A promise which resolves once the response is sent


Expand All @@ -87,18 +87,18 @@ Edits the previous response to this interaction and overwrites it. The status of

|Parameter|Type |Description|Required|
|---------|-------------------------------------|-----------|------|
|content|string or [MessageEmbed](https://discord.js.org/#/docs/main/stable/class/MessageEmbed) or [WebhookEditMessageOptions](https://discord.js.org/#/docs/main/stable/typedef/WebhookEditMessageOptions)|The new message content to overwrite the previous message with.|yes|
|content|string or [EmbedBuilder](https://discord.js.org/#/docs/discord.js/main/class/EmbedBuilder) or [InteractionEditReplyOptions](https://discord.js.org/#/docs/discord.js/main/typedef/InteractionEditReplyOptions)|The new message content to overwrite the previous message with.|yes|

**Returns:** `Promise<`[Message](https://discord.js.org/#/docs/main/stable/class/Message)` | void>`
**Returns:** `Promise<`[Message](https://discord.js.org/#/docs/main/stable/class/Message)`>`
A promise for the edited reply message

### .followUp(content, ?hidden)
Follows up the previous response with another one. Can be useful for sending a later response or giving an update to the user about the status of the previous request.

|Parameter|Type |Description|Required|
|---------|-------------------------------------|-----------|------|
|content|string or [MessageEmbed](https://discord.js.org/#/docs/main/stable/class/MessageEmbed) or [InteractionReplyOptions](https://discord.js.org/#/docs/main/stable/typedef/InteractionReplyOptions)|What to follow up the message with.|yes|
|hidden|boolean|Whether this message will be visible only to the sender|no (default `false`)|
|content|string or [EmbedBuilder](https://discord.js.org/#/docs/discord.js/main/class/EmbedBuilder) or [InteractionReplyOptions](https://discord.js.org/#/docs/main/stable/typedef/InteractionReplyOptions)|What to follow up the message with.|yes|
|hidden|boolean|Whether this message will be visible only to the sender [(ephemeral repsonse)](https://discordjs.guide/slash-commands/response-methods.html#ephemeral-responses)|no (default `false`)|

**Returns:** `Promise<`[Message](https://discord.js.org/#/docs/main/stable/class/Message)`>`
A promise for the sent follow up message
Expand All @@ -108,9 +108,9 @@ Shows the given modal to the user, and resolves once the user has submitted a re

|Parameter|Type |Description|Required|
|---------|-------------------------------------|-----------|------|
|modal|[Modal](https://discord.js.org/#/docs/discord.js/stable/class/Modal) or [ModalOptions](https://discord.js.org/#/docs/discord.js/stable/typedef/ModalOptions)|The modal to show to the user.|yes|
|modal|[ModalBuilder](https://discord.js.org/#/docs/discord.js/main/class/ModalBuilder)|The modal to show to the user.|yes|
|timeout|number|The number of milliseconds to wait for a response before timing out.|no (default 10 minutes)|
|options|[AwaitModalSubmitOptions](https://discord.js.org/#/docs/discord.js/stable/typedef/AwaitModalSubmitOptions)|Other options to send to the internal modal await. Some properties such as filter and time are overwritten.|no (default `null`)|

**Returns:** `Promise<`[ModalSubmitInteraction](https://discord.js.org/#/docs/main/stable/class/ModalSubmitInteraction)`>`
A promise for the modal submit interaction, which contains the entered text.
A promise for the modal submit interaction, which contains the entered text.
2 changes: 1 addition & 1 deletion docs/api/CommandOptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Determines if a given option has been set by the user. This can be used to clean

e.g.
```js
client.on("command", async (ctx) => {
client.on(SlasherEvents.CommandCreate, async (ctx) => {
// greet the name if it exists
if(ctx.options.has("name")) {
await ctx.reply("Hello " + ctx.options.getString("name"));
Expand Down
11 changes: 6 additions & 5 deletions docs/api/SlasherClient.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
2. [Methods](#methods)
1. [.login()](#login)
3. [Events](#events)
1. [command](#command)
1. [CommandCreate](#commandcreate)

## Import
JavaScript (pre ES6)
Expand All @@ -28,9 +28,9 @@ let client = new SlasherClient({ token: ... });
```
```js
// automatically reads the token from auth.json
let client = new SlasherClient({ useAuth: true });
let client = new SlasherClient();
```
However the options parameter extends discord.js' [ClientOptions](https://discord.js.org/#/docs/main/stable/typedef/ClientOptions) interface, so any valid options for discord.js will also work (e.g. sharding).
However the options parameter extends discord.js' [ClientOptions](https://discord.js.org/#/docs/main/stable/typedef/ClientOptions) interface, so any valid options for discord.js will also work (e.g. more intents, partials, sharding).

|Parameter|Type |Description|
|---------|-------------------------------------|-----------|
Expand All @@ -47,12 +47,13 @@ A promise for the token of the bot
Also see: [Inherited methods from Client](https://discord.js.org/#/docs/main/stable/class/Client?scrollTo=destroy)

## Events
For a complete list of events see [SlasherEvents](./SlasherEvents.md).

### command
### [CommandCreate](./SlasherEvents.md#commandcreate)
Emitted when a slash command is executed by a user using the bot. Passes a context object which provides most of the data needed to interact with the command and designed to simplify most checks and operations.

|Parameter|Type |Description|
|---------|-------------------------------------|-----------|
|context |[CommandContext](./CommandContext.md)|The context object for the executed command|

Also see: [Inherited events from Client](https://discord.js.org/#/docs/main/stable/class/Client?scrollTo=e-applicationCommandCreate)
Also see: [Inherited events from Client](https://discord.js.org/#/docs/main/stable/class/Client?scrollTo=e-apiRequest)
2 changes: 1 addition & 1 deletion docs/api/SlasherClientOptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ string


### ?useAuth
When this property is set to true, the client will read the bot token from the `auth.json` file in the root directory of your project. This file will be automatically created by the `slasher` CLI tool when uploading your commands to Discord if you choose.
When this property is set to true, the client will read the bot token from the `auth.json` file in the root directory of your project. This file will be automatically created by the `slasher` CLI tool when uploading your commands to Discord if you choose. This option is the default unless a `token` is provided.

**Type**
boolean
Expand Down
26 changes: 26 additions & 0 deletions docs/api/SlasherEvents.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# SlasherEvents
`SlasherEvents` is a enum which provides predefined constants for the predefined events which can be fired or listened to on [SlasherClient](./SlasherClient.md) instances. It currently only contains one event, but more may be added in future when necessary.

**Table of Contents**
1. [Import](#import)
2. [Enum Values](#enum-values)
1. [.CommandCreate](#commandcreate)

## Import
JavaScript (pre ES6)
```js
const { SlasherEvents } = require("discord.js-slasher");
```

TypeScript
```typescript
import { SlasherEvents } from 'discord.js-slasher';
```

## Enum Values

### .CommandCreate
Fired when a user sends a command to the bot. This is called in tandem with the [Events.InteractionCreate](https://discord.js.org/#/docs/discord.js/main/typedef/Events) event in vanilla discord.js, but it adds the [CommandContext](./CommandContext.md) utility object. For an example on how to use this event, see [Getting Started](../guides/getting-started.md).

**Value**
`"command"`
Loading

0 comments on commit 4093fc4

Please sign in to comment.