WOKCommands
Search…
Command initialization method
Some commands may require you to run code when they are loaded. This will often include create a basic listener, or fetching data from some source.
You can use the init() method within your command to handle this type of functionality:
JavaScript
TypeScript
ping.js
1
module.exports = {
2
// Best practice for the built-in help menu
3
category: 'Testing',
4
description: 'Replies with "Pong!"',
5
6
// This method is invoked only once whenever the command is registered
7
// "client" is the client object for your bot
8
// "instance" is your WOKCommands instance
9
init: (client, instance) => {
10
console.log('ran only one time when the bot starts up')
11
},
12
13
// This method is invoked anytime the command is ran
14
callback: ({ message }) => {
15
message.reply({
16
content: 'Pong!'
17
})
18
}
19
}
Copied!
ping.ts
1
import { ICommand } from 'wokcommands'
2
3
export default {
4
// Best practice for the built-in help menu
5
category: 'Testing',
6
description: 'Replies with "Pong!"',
7
8
// This method is invoked only once whenever the command is registered
9
// "client" is the client object for your bot
10
// "instance" is your WOKCommands instance
11
init: (client, instance) => {
12
console.log('ran only one time when the bot starts up')
13
},
14
15
// This method is invoked anytime the command is ran
16
callback: ({ message }) => {
17
message.reply({
18
'Pong!'
19
})
20
}
21
} as ICommand
Copied!
Copy link