How to subscribe to events (topic created, topic closed, etc..)

AI-generated summary

There is no official list of available events to subscribe to using the onAppEvent function in Discourse plugin development. However, zogstrip suggests searching the source code for these events. j127 attempted to do this by grepping for onAppEvent, but found limited results. phallguy recommends searching for \.trigger\( instead, which can help identify where events are actually fired.

I am currently creating a plugin and was wondering how to subscribe to different events.

initializePlugin() exposes an api object that has the function onAppEvent(name, fn).

Is there a list somewhere with the name of the events one can subscribe to?

Your best shot at an up-to-date list is to grep the source code for these events.

What is the best way to find them? I’m searching for onAppEvent but that isn’t turning up much:

$ grep -r onAppEvent *
app/assets/javascripts/discourse/lib/plugin-api.js.es6:    this.onAppEvent("page:changed", data => fn(data.url, data.title));
app/assets/javascripts/discourse/lib/plugin-api.js.es6:      api.onAppEvent('inserted-custom-html', () => {
app/assets/javascripts/discourse/lib/plugin-api.js.es6:  onAppEvent(name, fn) {
jsapp/lib/plugin-api.js.es6:    this.onAppEvent("page:changed", data => fn(data.url, data.title));
jsapp/lib/plugin-api.js.es6:      api.onAppEvent('inserted-custom-html', () => {
jsapp/lib/plugin-api.js.es6:  onAppEvent(name, fn) {

I was doing some digging as well and found that searching for \.trigger\( produced a list of where events are actually fired.