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
module.exports = {
// Best practice for the built-in help menu
category: 'Testing',
description: 'Replies with "Pong!"',
// This method is invoked only once whenever the command is registered
// "client" is the client object for your bot
// "instance" is your WOKCommands instance
init: (client, instance) => {
console.log('ran only one time when the bot starts up')
},
// This method is invoked anytime the command is ran
callback: ({ message }) => {
message.reply({
content: 'Pong!'
})
}
}
ping.ts
import { ICommand } from 'wokcommands'
export default {
// Best practice for the built-in help menu
category: 'Testing',
description: 'Replies with "Pong!"',
// This method is invoked only once whenever the command is registered
// "client" is the client object for your bot
// "instance" is your WOKCommands instance
init: (client, instance) => {
console.log('ran only one time when the bot starts up')
},
// This method is invoked anytime the command is ran
callback: ({ message }) => {
message.reply({
'Pong!'
})
}
} as ICommand
Copy link