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
const DiscordJS = require('discord.js')
const WOKCommands = require('wokcommands')
const path = require('path')
const { Intents } = DiscordJS
const client = new DiscordJS.Client({
// These intents are recommended for the built in help menu
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
],
})
client.on('ready', () => {
new WOKCommands(client, {
// The name of the local folder for your command files
commandsDir: path.join(__dirname, 'commands'),
// What guilds your slash commands will be created in
testServers: ['YOUR TEST GUILD ID HERE']
})
})
client.login('YOUR TOKEN HERE')
index.ts
import DiscordJS, { Intents } from 'discord.js'
import WOKCommands from 'wokcommands'
import path from 'path'
const client = new DiscordJS.Client({
// These intents are recommended for the built in help menu
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
],
})
client.on('ready', () => {
new WOKCommands(client, {
// The name of the local folder for your command files
commandsDir: path.join(__dirname, 'commands'),
// Allow importing of .ts files if you are using ts-node
typeScript: true,
// What guilds your slash commands will be created in
testServers: ['YOUR TEST GUILD ID HERE']
})
})
client.login('YOUR TOKEN HERE')
Then create a "commands" folder where you can create a "ping.js" file with the following contents:
JavaScript
TypeScript
ping.js
module.exports = {
category: 'Testing',
description: 'Replies with pong', // Required for slash commands
slash: 'both', // Create both a slash and legacy command
testOnly: true, // Only register a slash command for the testing guilds
callback: ({ message, interaction }) => {
const reply = 'Pong!'
// message is provided only for a legacy command
if (message) {
message.reply({
content: reply
})
return
}
// interaction is provided only for a slash command
interaction.reply({
content: reply
})
// Alternatively we can just simply return our reply object
// OR just a string as the content.
// WOKCommands will handle the proper way to reply with it
return {
content: reply
}
},
}
ping.ts
import { ICommand } from 'wokcommands'
export default {
category: 'Testing',
description: 'Replies with pong', // Required for slash commands
slash: 'both', // Create both a slash and legacy command
testOnly: true, // Only register a slash command for the testing guilds
callback: ({ message, interaction }) => {
const reply = 'Pong!'
// message is provided for a legacy command
if (message) {
message.reply({
content: reply
})
return
}
// interaction is provided for slash commands
interaction.reply({
content: reply
})
// Alternatively we can just simply return our reply object
// OR just a string as the content.
// WOKCommands will handle the proper way to reply with it
return {
content: reply
}
},
} as ICommand
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