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
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
// Ran whenever a supported database connection is connected
23
wok.on('databaseConnected', (connection, state) => {
24
console.log(`The connection state is "${state}"`)
25
})
26
})
27
28
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
// Ran whenever a supported database connection is connected
23
wok.on('databaseConnected', (connection, state) => {
24
console.log(`The connection state is "${state}"`)
25
})
26
})
27
28
client.login('YOUR TOKEN HERE')
Copied!

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
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
// Ran when a server owner attempts to set a language that you haven't supported
23
wok.on('languageNotSupported', (guild, lang) => {
24
console.log(`"${guild.name}" Attempted to set language to "${lang}"`)
25
})
26
})
27
28
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
})
19
20
// Ran when a server owner attempts to set a language that you haven't supported
21
wok.on('languageNotSupported', (guild, lang) => {
22
console.log(`"${guild.name}" Attempted to set language to "${lang}"`)
23
})
24
})
25
26
client.login('YOUR TOKEN HERE')
Copied!

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
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
// Ran when an exception occurs within a command
23
wok.on('commandException', (command, message, error) => {
24
console.log(`An exception occured when using command "${command.names[0]}"! The error is:`)
25
console.error(error)
26
})
27
})
28
29
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
})
19
20
// Ran when an exception occurs within a command
21
wok.on('commandException', (command, message, error) => {
22
console.log(`An exception occured when using command "${command.names[0]}"! The error is:`)
23
console.error(error)
24
})
25
})
26
27
client.login('YOUR TOKEN HERE')
Copied!

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
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
})
21
22
// Ran when a message is sent or updated
23
// NOTE: This is ran on the client and not the WOKCommands instance
24
client.on('messageUpsert', (message, oldMessage) => {
25
// oldMessage is undefined if it is a new message
26
// wasUpdated is now boolean true if it was an updated message
27
const wasUpdated = !!oldMessage
28
console.log(`The new content is ${message.content}.`)
29
})
30
})
31
32
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
})
19
20
// Ran when a message is sent or updated
21
// NOTE: This is ran on the client and not the WOKCommands instance
22
client.on('messageUpsert', (message, oldMessage) => {
23
// oldMessage is undefined if it is a new message
24
// wasUpdated is now boolean true if it was an updated message
25
const wasUpdated = !!oldMessage
26
console.log(`The new content is ${message.content}.`)
27
})
28
})
29
30
client.login('YOUR TOKEN HERE')
Copied!