WOKCommands
Search…
Custom events
WOKCommands comes with some custom events that help make our lives as developers easier.

databaseConnected Event

This event is fired whenever a database is successfully connected via WOKCommands. For more information on how to connect to database please see the "DATABASES" section of this documentation.
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')
})
// Ran whenever a supported database connection is connected
wok.on('databaseConnected', (connection, state) => {
console.log(`The connection state is "${state}"`)
})
})
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,
})
// Ran whenever a supported database connection is connected
wok.on('databaseConnected', (connection, state) => {
console.log(`The connection state is "${state}"`)
})
})
client.login('YOUR TOKEN HERE')

languageNotSupported Event

Server owners may often choose your bot to use a language that you have not supported yet. You can listen to the "languageNotSupported" event and log these to know what types of languages your users want.
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')
})
// Ran when a server owner attempts to set a language that you haven't supported
wok.on('languageNotSupported', (guild, lang) => {
console.log(`"${guild.name}" Attempted to set language to "${lang}"`)
})
})
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'),
})
// Ran when a server owner attempts to set a language that you haven't supported
wok.on('languageNotSupported', (guild, lang) => {
console.log(`"${guild.name}" Attempted to set language to "${lang}"`)
})
})
client.login('YOUR TOKEN HERE')

commandException Event

This event is fired whenever an exception occurs within one of your commands. You can use this information to log error details or provide a meaningful message to the user.
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')
})
// Ran when an exception occurs within a command
wok.on('commandException', (command, message, error) => {
console.log(`An exception occured when using command "${command.names[0]}"! The error is:`)
console.error(error)
})
})
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'),
})
// Ran when an exception occurs within a command
wok.on('commandException', (command, message, error) => {
console.log(`An exception occured when using command "${command.names[0]}"! The error is:`)
console.error(error)
})
})
client.login('YOUR TOKEN HERE')

messageUpsert Event

Unlike previous events, this one is fired from the normal client object for your bot instead of the WOKCommands instance. This event is fired whenever a new message is sent OR an existing message is updated. This is a combination of message and messageUpdate events from the Discord.JS library.
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')
})
// Ran when a message is sent or updated
// NOTE: This is ran on the client and not the WOKCommands instance
client.on('messageUpsert', (message, oldMessage) => {
// oldMessage is undefined if it is a new message
// wasUpdated is now boolean true if it was an updated message
const wasUpdated = !!oldMessage
console.log(`The new content is ${message.content}.`)
})
})
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'),
})
// Ran when a message is sent or updated
// NOTE: This is ran on the client and not the WOKCommands instance
client.on('messageUpsert', (message, oldMessage) => {
// oldMessage is undefined if it is a new message
// wasUpdated is now boolean true if it was an updated message
const wasUpdated = !!oldMessage
console.log(`The new content is ${message.content}.`)
})
})
client.login('YOUR TOKEN HERE')