Skip to content
This repository has been archived by the owner on Sep 3, 2021. It is now read-only.

Latest commit

History

History
38 lines (25 loc) 路 846 Bytes

middleware.md

File metadata and controls

38 lines (25 loc) 路 846 Bytes

Hershel

Middleware

The middleware system is provided by koa-compose. I recommend reading this article to learn about its extremely powerful middleware system.

const { Client } = require('hershel')

const bot = new Client({
  logger: {
    level: 'info',
    stream: myStream,
  },
})

bot.use(({ id }, next) => {
  console.log(`#${id}`)

  next()
})

// assert.stricEqual(bot.middleware.length, 1)

await bot.login(TOKEN)

// assert.stricEqual(bot.started, true)

bot.use(({ message }, next) => {
  console.log(message.content)

  next()
})

// ERROR: Cannot add new middleware while client is already started

Once the client has started, the middleware stack is sealed and can no longer be modified.