Skip to main content

️💼 Session Manager

The SessionManager is the object that holds together the nyx session system.

It consists of:

  • SessionCustomIdCodec for encoding and decoding custom session ids.
  • SessionUpdateSubscriber for listening to session updates.
  • SessionRepository for storing sessions.
  • SessionExecutor for executing sessions.
  • SessionPromiseRepository for storing session end promises.
  • EventBus for emitting session related events.

As well as methods to interact with them.

👷 Creation

You can create a custom session manager by either:

  • Extending DefaultSessionManager from @nyx-discord/framework (recommended).
  • Implementing SessionManager from @nyx-discord/core.

Then you can pass it to your bot:

class MySessionManager extends DefaultSessionManager {
public myCustomPublicMethod() {}
}

const myBot = Bot.create((bot: NyxBot) => ({
// ...

sessions: new MySessionManager(/** ... */),
}));

mybot.getSessionManager().myCustomPublicMethod() // works!

The Bot class is able to infer the type of your custom manager via generics, so accessing any custom public method or property will work without errors.