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
1
module.exports = {
2
// Best practice for the built-in help menu
3
category: 'Math',
4
description: 'Adds two numbers together',
5
6
// This will now only work in test servers
7
// We can specify test servers in the next code snippet
8
testOnly: true,
9
10
// For the correct usage of the command
11
expectedArgs: '<number1> <number2>',
12
minArgs: 2,
13
maxArgs: 2,
14
syntaxError: 'Incorrect usage! Please use "{PREFIX}add {ARGUMENTS}"',
15
16
// Invoked when the command is actually ran
17
callback: ({ channel, args }) => {
18
// Convert the arguments into numbers
19
const number1 = parseInt(args[0])
20
const number2 = parseInt(args[1])
21
22
const sum = number1 + number2;
23
24
// Reply with the sum
25
channel.send({
26
content: `The sum is ${sum}`
27
})
28
}
29
}
Copied!
add.ts
1
import { ICommand } from 'wokcommands'
2
3
export default {
4
// Best practice for the built-in help menu
5
category: 'Math',
6
description: 'Adds two numbers together',
7
8
// This will now only work in test servers
9
// We can specify test servers in the next code snippet
10
testOnly: true,
11
12
// For the correct usage of the command
13
expectedArgs: '<number1> <number2>',
14
minArgs: 2,
15
maxArgs: 2,
16
syntaxError: 'Incorrect usage! Please use "{PREFIX}add {ARGUMENTS}"',
17
18
// Invoked when the command is actually ran
19
callback: ({ channel, args }) => {
20
// Convert the arguments into numbers
21
const number1 = parseInt(args[0])
22
const number2 = parseInt(args[1])
23
24
const sum = number1 + number2;
25
26
// Reply with the sum
27
channel.send({
28
content: `The sum is ${sum}`
29
})
30
}
31
} as ICommand
Copied!
You can then specify any amount of server/guild IDs when initializing WOKCommands like so:
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 server/guild IDs are test servers
21
// You can use a single string if you only have one as well
22
testServers: ['464316540490088448', 'another ID', 'another ID']
23
})
24
})
25
26
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 server/guild IDs are test servers
21
// You can use a single string if you only have one as well
22
testServers: ['464316540490088448', 'another ID', 'another ID']
23
})
24
})
25
26
client.login('YOUR TOKEN HERE')
Copied!
Copy link