2.0.0 • Published 2 years ago

djs-slash-helper v2.0.0

Weekly downloads
-
License
BSD-2-Clause
Repository
github
Last release
2 years ago

djs-slash-helper

Handles the faffy bit of setting up interaction-based command with Discord.js

Usage

Defining command objects

Commands follow Discord's native format by implementing Command<T>.

import {InteractionFor} from './command.js'
import {MessageInteraction} from 'discord.js'

const command: Command<ApplicationCommandType.ChatInput> = {
	type: ApplicationCommandType.ChatInput,
	name: 'example',
	description: 'Example command',
	options: [{
		type: ApplicationCommandOptionType.String,
		name: "exampleArg",
		description: "hello",
	}],
	permissions: [{
		type: "ROLE",
		id: "role-id-goes-here",
		permission: true
	}],
	// optional, defaults to true
	default_permission: false,

	// this function may return anything and/or be async.
	// the type of interaction changes depending on the type
	// set earlier, see InteractionFor<T>
	handle(interaction: MessageInteraction) {
		// do something
	}
}

Registering commands

const manager = new CommandManager([yourCommand, anotherCommand], client);

// set up your bot first and set a token
await manager.setupGlobally('your-client-id');
// or
await manager.setupForGuild('your-client-id', 'your-guild-id')

Using subcommands

import {MessageInteraction} from 'discord.js'

const command: Command<ApplicationCommandType.ChatInput> = {
	// ...
    // you may also nest subcommands inside groups
	options: [{
		type: ApplicationCommandOptionType.Subcommand,
		name: "exampleArg",
		description: "hello",
		async handle(interaction: MessageInteraction) {
			// do something
		}
	}],
    // this method should be defined, however it will not be called
    // when subcommands are present
    handle() {}
}
2.0.0

2 years ago

1.2.0

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.1

2 years ago