Skip to content

ExtendedListener

GoldenDelicios edited this page Jun 5, 2022 · 3 revisions

ExtendedListener is an implementation of JDA's event listener with two improvements: 1) exception handling and 2) modularity.

  1. If a module encounters an unhandled exception while handling a JDA event, the exception and its corresponding stack trace is reported to the bot owners.
  2. Each module can be enabled or disabled, either on startup or during runtime, except for ManagerListener.
  3. Any tasks scheduled by a module are automatically canceled when it is disabled.

All modules in Modbot extend ExtendedListener or its subclass, CommandListener.

Methods

The following are methods in ExtendedListener that may be overridden by subclasses.

onEnable()

This method runs when a disabled module is enabled, but only if JDA is "ready" (i.e. this module received a ReadyEvent). This guarantees that all Discord entities are fully loaded in. If JDA is not ready (usually because the module was enabled on startup), this method will run as soon as it is.

onDisable()

This method runs when an enabled module is disabled. This can be overridden to save any unsaved data.

reload()

This method is run when a disabled module is enabled, or after the /reload command is run. This runs after onEnable. This may return a non-empty string to display to the user if an error occurs while reloading.

save()

Currently, this method is never called externally. However, modules frequently override this method with code to save their data to file.

Clone this wiki locally