WOKCommands
Search…
Message handler
The message handler class handles all of the customizable messages and translations in WOKCommands. To access it's instance you can use the following:
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
const wok = new WOKCommands(client, {
18
// The name of the local folder for your command files
19
commandsDir: path.join(__dirname, 'commands')
20
})
21
22
const { messageHandler } = wok
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
const wok = 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
})
21
22
const { messageHandler } = wok
23
})
24
25
client.login('YOUR TOKEN HERE')
Copied!
You can then use the following methods:
The structure of this code is for demonstration purposes only. Do not copy/paste this code, it will not work.
1
class MessageHandler {
2
// Returns an array of languages supported by your bot
3
public languages(): string[];
4
5
// Returns eithe the default language or the language for the guild
6
// depending on if the guild was null or not
7
public getLanguage(guild: Guild | null): string;
8
9
// Returns a "direct message" from messages.json
10
public get(
11
guild: Guild | null, // For translations
12
messageId: string, // The name of the field in messages.json
13
args?: { [key: string]: string }
14
): string;
15
16
// Returns an "embed message" from messages.json
17
public getEmbed(
18
guild: Guild | null, // For translations
19
embedId: string, // The name of the field in messages.json
20
itemId: string, // The nested object for the embed in messages.json
21
args?: { [key: string]: string }
22
);
23
}
Copied!
Copy link