WOKCommands
Search…
Slash commands
WOKCommands has support for the new Slash Commands feature, however you may want more control over your slash commands. You can access the slash command handler instance by using the following:
JavaScript
TypeScript
index.js
1
const DiscordJS = require('discord.js')
2
const WOKCommands = require('wokcommands')
3
const path = require('path')
4
5
const { Intents } = DiscordJS
6
7
const client = new DiscordJS.Client({
8
// These intents are recommended for the built in help menu
9
intents: [
10
Intents.FLAGS.GUILDS,
11
Intents.FLAGS.GUILD_MESSAGES,
12
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
13
],
14
})
15
16
client.on('ready', () => {
17
const wok = new WOKCommands(client, {
18
// The name of the local folder for your command files
19
commandsDir: path.join(__dirname, 'commands')
20
})
21
22
const { slashCommands } = wok
23
})
24
25
client.login('YOUR TOKEN HERE')
Copied!
index.ts
1
import DiscordJS, { Intents } from 'discord.js'
2
import WOKCommands from 'wokcommands'
3
import path from 'path'
4
5
const client = new DiscordJS.Client({
6
// These intents are recommended for the built in help menu
7
intents: [
8
Intents.FLAGS.GUILDS,
9
Intents.FLAGS.GUILD_MESSAGES,
10
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
11
],
12
})
13
14
client.on('ready', () => {
15
const wok = new WOKCommands(client, {
16
// The name of the local folder for your command files
17
commandsDir: path.join(__dirname, 'commands'),
18
// Allow importing of .ts files if you are using ts-node
19
typeScript: true,
20
})
21
22
const { slashCommands } = wok
23
})
24
25
client.login('YOUR TOKEN HERE')
Copied!
Once you have access to the instance you can use the following methods:
The structure of this code is for demonstration purposes only. Do not copy/paste this code, it will not work.
1
class SlashCommands {
2
// Get all global slash commands OR slash commands registered to a
3
// specific guild.
4
public async get(guildId?: string): Promise<Map<any, any>>;
5
6
// Deletes a global or guild specific slash command
7
public async delete(commandId: string, guildId?: string): Promise<ApplicationCommand<{}> | undefined>;
8
}
Copied!

Custom Slash Command Options

In a normal slash command you can specify your own options. WOKCommands give you the option to do this directly in the command using the same syntax:
JavaScript
TypeScript
ping.js
1
module.exports = {
2
category: 'test', // Required for slash commands
3
description: 'Adds two numbers together', // Required for slash commands
4
5
slash: 'both',
6
testOnly: true, // Ensure you have test servers setup
7
8
minArgs: 2,
9
expectedArgs: '<num1> <num2>',
10
11
options: [
12
{
13
name: 'num1',
14
description: 'The first number.',
15
required: true,
16
type: 10,
17
},
18
{
19
name: 'num2',
20
description: 'The second number',
21
required: true,
22
type: 10,
23
},
24
],
25
26
callback: ({ args }) => {
27
const num1 = parseInt(args[0])
28
const num2 = parseInt(args[1])
29
30
return `The sum is ${num1 + num2}`
31
},
32
}
Copied!
ping.ts
1
import DiscordJS from 'discord.js'
2
import { ICommand } from '../../wokcommands/typings'
3
4
export default {
5
category: 'test', // Required for slash commands
6
description: 'Adds two numbers together', // Required for slash commands
7
8
slash: 'both',
9
testOnly: true, // Ensure you have test servers setup
10
11
minArgs: 2,
12
expectedArgs: '<num1> <num2>',
13
14
options: [
15
{
16
name: 'num1',
17
description: 'The first number.',
18
required: true,
19
type: DiscordJS.Constants.ApplicationCommandOptionTypes.NUMBER,
20
},
21
{
22
name: 'num2',
23
description: 'The second number',
24
required: true,
25
type: DiscordJS.Constants.ApplicationCommandOptionTypes.NUMBER,
26
},
27
],
28
29
callback: ({ args }) => {
30
const num1 = parseInt(args[0])
31
const num2 = parseInt(args[1])
32
33
return `The sum is ${num1 + num2}`
34
},
35
} as ICommand
Copied!
WOKCommands will normally try to create its own options object from the other arguments such as minArgs, expectedArgs, etc. WOKCommands won't try to create its own options object if you provide your own custom options object like this.

Deleting slash commands

WOKCommands comes with a built-in !slash command that will list all global and per-guild slash commands. To delete a slash command you can run the following: !slash [command-id].