Service
Description
Stateful business logic living outside of Middleware
Example
class IncrementService extends Service {
serviceDidInitialize() {
this.counter = 0
this.increment = () => this.counter++
}
}
const command = new CommandBuilder()
.match(matchPrefixes("increment"))
.use((context) => {
const { manager } = context
const service = manager.getService(IncrementService)
service.increment()
console.log("The counter is now", service.counter)
})
.done()
const bot = new Bot({
services: [IncrementService],
commands: [command],
})
// Input: "increment"
// Output: "The counter is now 1"
// Input: "increment"
// Output: "The counter is now 2"
Generics
M
C
Constructor
warning
Do not manually instantiate a service. Services are automatically instantiated by the ServiceManagernew Service(options, s)
Parameters
options:
ServiceOptions<M, C>s:
symbolProperties
bot:
Bot<M, C>manager:
ServiceManager<M, C>Methods
Middleware