WOKCommands
Search…
Test servers
You may want some commands to only be enabled in specific servers/guilds for testing. This will give you a good idea if something is working in a production environment without risking bugs for your other users.
You can easily specify a command as a "test only" command like so:
JavaScript
TypeScript
add.js
module.exports = {
// Best practice for the built-in help menu
category: 'Math',
description: 'Adds two numbers together',
// This will now only work in test servers
// We can specify test servers in the next code snippet
testOnly: true,
// For the correct usage of the command
expectedArgs: '<number1> <number2>',
minArgs: 2,
maxArgs: 2,
syntaxError: 'Incorrect usage! Please use "{PREFIX}add {ARGUMENTS}"',
// Invoked when the command is actually ran
callback: ({ channel, args }) => {
// Convert the arguments into numbers
const number1 = parseInt(args[0])
const number2 = parseInt(args[1])
const sum = number1 + number2;
// Reply with the sum
channel.send({
content: `The sum is ${sum}`
})
}
}
add.ts
import { ICommand } from 'wokcommands'
export default {
// Best practice for the built-in help menu
category: 'Math',
description: 'Adds two numbers together',
// This will now only work in test servers
// We can specify test servers in the next code snippet
testOnly: true,
// For the correct usage of the command
expectedArgs: '<number1> <number2>',
minArgs: 2,
maxArgs: 2,
syntaxError: 'Incorrect usage! Please use "{PREFIX}add {ARGUMENTS}"',
// Invoked when the command is actually ran
callback: ({ channel, args }) => {
// Convert the arguments into numbers
const number1 = parseInt(args[0])
const number2 = parseInt(args[1])
const sum = number1 + number2;
// Reply with the sum
channel.send({
content: `The sum is ${sum}`
})
}
} as ICommand
You can then specify any amount of server/guild IDs when initializing WOKCommands like so:
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 server/guild IDs are test servers
// You can use a single string if you only have one as well
testServers: ['464316540490088448', 'another ID', 'another ID']
})
})
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 server/guild IDs are test servers
// You can use a single string if you only have one as well
testServers: ['464316540490088448', 'another ID', 'another ID']
})
})
client.login('YOUR TOKEN HERE')
Copy link