The databaseConnected, commandException and handlerReady events are enabled by default.
But there are one more event: commandDevsOnly that is only enabled when you set the useDefaultMessages property to false when creating the handler. It let you handle command checks the way you want.
handlerReady
This event is emitted once when the handler set up is done.
const { Event } = require('sl-commands')
/** ctx is a object containing the client and the handler instances */
new Event(
'handlerReady',
(ctx) => {
console.log(`The handler is ready!`)
}
)
import { Event } from 'sl-commands'
/** ctx is a object containing the client and the handler instances */
new Event(
'handlerReady',
(ctx) => {
console.log(`The handler is ready!`)
}
)
databaseConnected
This event is emitted whenever the database is sucessfully connected via SLCommands.
const { Event } = require('sl-commands')
/** ctx is a object containing the client and the handler instances */
new Event(
'databaseConnected',
(ctx, connection, state) => {
console.log(`The connection state is "${state}".`)
}
)
import { Event } from 'sl-commands'
/** ctx is a object containing the client and the handler instances */
new Event(
'databaseConnected',
(ctx, connection, state) => {
console.log(`The connection state is "${state}".`)
}
)
commandException
This is emitted whenever the handler detects any exception with the commands.
const { Event } = require('sl-commands')
/** ctx is a object containing the client and the handler instances */
/** interaction parameter can be undefined */
new Event(
'commandException',
(ctx, commandName, error, interaction) => {
console.log(`Error in command ${commandName}.`, error)
if (interaction) {
interaction.reply({ content: 'Oops! An error occurred.' })
}
}
)
import { Event } from 'sl-commands'
/** ctx is a object containing the client and the handler instances */
/** interaction parameter can be undefined */
new Event(
'commandException',
(ctx, commandName, error, interaction) => {
console.log(`Error in command ${commandName}.`, error)
if (interaction) {
interaction.reply({ content: 'Oops! An error occurred.' })
}
}
)
commandDevsOnly
This is emitted whenever some unauthorized user tries to use a devsOnly command.
const { Event } = require('sl-commands')
/** ctx is a object containing the client and the handler instances */
new Event(
'commandDevsOnly',
(ctx, interaction) => {
interaction.reply({ content: 'This command can only be used by my devs.' })
}
)
import { Event } from 'sl-commands'
/** ctx is a object containing the client and the handler instances */
new Event(
'commandDevsOnly',
(ctx, interaction) => {
interaction.reply({ content: 'This command can only be used by my devs.' })
}
)