WOKCommands
Search…
Ping pong command example
WOKCommands is easy to get setup and working. On this page you will learn how to create a simple "Ping -> Pong" command example.
First you must setup WOKCommands in your main file:
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
new WOKCommands(client, {
18
// The name of the local folder for your command files
19
commandsDir: path.join(__dirname, 'commands'),
20
// What guilds your slash commands will be created in
21
testServers: ['YOUR TEST GUILD ID HERE']
22
})
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
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
// What guilds your slash commands will be created in
21
testServers: ['YOUR TEST GUILD ID HERE']
22
})
23
})
24
25
client.login('YOUR TOKEN HERE')
Copied!
Then create a "commands" folder where you can create a "ping.js" file with the following contents:
JavaScript
TypeScript
ping.js
1
module.exports = {
2
category: 'Testing',
3
description: 'Replies with pong', // Required for slash commands
4
5
slash: 'both', // Create both a slash and legacy command
6
testOnly: true, // Only register a slash command for the testing guilds
7
8
callback: ({ message, interaction }) => {
9
const reply = 'Pong!'
10
11
// message is provided only for a legacy command
12
if (message) {
13
message.reply({
14
content: reply
15
})
16
return
17
}
18
19
// interaction is provided only for a slash command
20
interaction.reply({
21
content: reply
22
})
23
24
// Alternatively we can just simply return our reply object
25
// OR just a string as the content.
26
// WOKCommands will handle the proper way to reply with it
27
return {
28
content: reply
29
}
30
},
31
}
Copied!
ping.ts
1
import { ICommand } from 'wokcommands'
2
3
export default {
4
category: 'Testing',
5
description: 'Replies with pong', // Required for slash commands
6
7
slash: 'both', // Create both a slash and legacy command
8
testOnly: true, // Only register a slash command for the testing guilds
9
10
callback: ({ message, interaction }) => {
11
const reply = 'Pong!'
12
13
// message is provided for a legacy command
14
if (message) {
15
message.reply({
16
content: reply
17
})
18
return
19
}
20
21
// interaction is provided for slash commands
22
interaction.reply({
23
content: reply
24
})
25
26
// Alternatively we can just simply return our reply object
27
// OR just a string as the content.
28
// WOKCommands will handle the proper way to reply with it
29
return {
30
content: reply
31
}
32
},
33
} as ICommand
Copied!
You may receive a warning about no MongoDB URI being provided, you can ignore it for this example.
The category property is for the built-in help menu. This property is optional but will create a warning in the console. The description property is also used in the built-in help menu to provide more information about the command, however the description property is required if your command will be a slash command. All commands are encouraged to have both a category and description.
After inviting your bot to a Discord server and running !ping ("!" is the default command prefix) or /ping within the specified test server, your bot should reply with Pong!.
Copy link