WOKCommands
Search…
Customizable messages & per-guild languages
WOKCommands offers the ability to customize messages as well as translate messages into different languages. Server/guild owners can then specify what language should be used in their server/guild.

Per-guild language configuration

Server owners can use the following command to set what language your bot should used:
!language [New Language]
Omitting the argument will display the current language in use. If the server owner is attempting to select a language that you have not supported yet then a custom event will be fired so you can listen for that information.

Storing custom messages and translations

As the developer you can create a messages.json file that contains your own text and translations. There are two types of objects within this file: direct messages and embeds. Direct messages will be a single message in different languages, while embeds will contain different types of fields. An example of each:
Direct Messages
1
{
2
"NEW_LANGUAGE": {
3
"english": "Language set to {LANGUAGE}.",
4
"spanish": "Idioma configurado en {LANGUAGE}."
5
}
6
}
Copied!
Embeds
1
{
2
"HELP_MENU": {
3
"TITLE": {
4
"english": "Help Menu",
5
"spanish": "Menú de ayuda"
6
}
7
}
8
}
Copied!
Currently embed support will only work with built-in embeds such as the built-in help menu. You cannot customize "direct messages" to become an embed with this file. The ability to do so will be added in the future.
You will also need to define where your messages.json file lives in the WOKCommands constructor like so:
index.js
1
new WOKCommands(client, , {
2
commandsDir: path.join(__dirname. 'commands'),
3
featuresDir: path.join(__dirname. 'features'),
4
messagesPath: path.join(__dirname. 'messages.json')
5
})
Copied!

Loading message text

You should not load text from your messages.json file directly, instead there is a built-in function to ensure the correct language is returned. A simple example:
messages.json snippet
1
{
2
"EXAMPLE": {
3
"english": "An example message",
4
"spanish": "Un mensaje de ejemplo"
5
}
6
}
Copied!
JavaScript
TypeScript
example.js
1
module.exports = {
2
category: 'Testing',
3
description: 'Example with language selection',
4
5
callback: ({ message, instance }) => {
6
const { guild } = message
7
message.reply(instance.messageHandler.get(guild, 'EXAMPLE'))
8
},
9
}
Copied!
example.js
1
import { ICommand } from 'wokcommands'
2
3
export default {
4
category: 'Testing',
5
description: 'Example with language selection',
6
7
callback: ({ message, instance }) => {
8
const { guild } = message
9
message.reply(instance.messageHandler.get(guild, 'EXAMPLE'))
10
},
11
} as ICommand
Copied!
If you ran the !example in a server it will reply with "An example message". If that server was configured to Spanish it will reply with "Un mensaje de ejemplo" instead.
You can set dynamic placeholders in your messages like so:
messages.json snippet
1
{
2
"EXAMPLE": {
3
"english": "An example message. {TEST}",
4
"spanish": "Un mensaje de ejemplo. {TEST}"
5
}
6
}
Copied!
You can then dynamically insert values like so:
JavaScript
TypeScript
example.js
1
module.exports = {
2
category: 'Testing',
3
description: 'Example with language selection',
4
5
callback: ({ message, instance }) => {
6
const { guild } = message
7
message.reply(instance.messageHandler.get(guild, 'EXAMPLE', {
8
TEST: 'hello world'
9
}))
10
},
11
}
Copied!
example.ts
1
import { ICommand } from 'wokcommands'
2
3
export default {
4
category: 'Testing',
5
description: 'Example with language selection',
6
7
callback: ({ message, instance }) => {
8
const { guild } = message
9
message.reply(instance.messageHandler.get(guild, 'EXAMPLE', {
10
TEST: 'hello world'
11
}))
12
},
13
} as ICommand
Copied!
Now running !example will now display "An example message. hello world".

Global syntax errors

In a lot of cases your syntax errors will be very similar. You can specify a global syntax error within your messages.json file like so:
messages.json snippet
1
{
2
"SYNTAX_ERROR": {
3
"english": "Incorrect usage! Please use \"{PREFIX}{COMMAND} {ARGUMENTS}\"",
4
"spanish": "¡Uso incorrecto! Utilice \"{PREFIX} {COMMAND} {ARGUMENTS}\""
5
},
6
}
Copied!
The {PREFIX}, {COMMAND} and {ARGUMENTS} must always be in upper case. These will be replaced with the correct content when an error occurs. The {ARGUMENTS} variable must be specified in the command like so:
JavaScript
TypeScript
ping.js
1
module.exports = {
2
category: 'Testing',
3
description: 'Replies with pong',
4
5
minArgs: 1,
6
maxArgs: -1, // -1 means no limit
7
expectedArgs: "<user @>",
8
9
callback: ({ message }) => {
10
message.reply('Pong!')
11
}
12
}
Copied!
ping.ts
1
import { ICommand } from 'wokcommands'
2
3
export default {
4
category: 'Testing',
5
description: 'Replies with pong',
6
7
minArgs: 1,
8
maxArgs: -1, // -1 means no limit
9
expectedArgs: "<user @>",
10
11
callback: ({ message }) => {
12
message.reply('Pong!')
13
}
14
} as ICommand
Copied!
A per-command syntax error message will always overwrite a global one for that specific command.