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
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', () => {
const wok = new WOKCommands(client, {
// The name of the local folder for your command files
commandsDir: path.join(__dirname, 'commands')
})
const { messageHandler } = wok
})
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', () => {
const wok = 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,
})
const { messageHandler } = wok
})
client.login('YOUR TOKEN HERE')
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.
class MessageHandler {
// Returns an array of languages supported by your bot
public languages(): string[];
// Returns eithe the default language or the language for the guild
// depending on if the guild was null or not
public getLanguage(guild: Guild | null): string;
// Returns a "direct message" from messages.json
public get(
guild: Guild | null, // For translations
messageId: string, // The name of the field in messages.json
args?: { [key: string]: string }
): string;
// Returns an "embed message" from messages.json
public getEmbed(
guild: Guild | null, // For translations
embedId: string, // The name of the field in messages.json
itemId: string, // The nested object for the embed in messages.json
args?: { [key: string]: string }
);
}
Copy link