What is Flux?
Discord manages its state with Flux: a central dispatcher broadcasts actions (a message arrives, a channel is selected, the user’s settings change), and stores listen for those actions and hold the resulting state. If you want to know what Discord currently knows (the current user, a guild, the selected channel) you read a store. If you want to know when something happens, you subscribe to the dispatcher. Both come from Metro: stores viafindStore, the dispatcher and common stores pre-resolved on metro.common and metro.stores.
Reading stores
A store is a singleton exposing getters over Discord’s state. Find it once (lazily, so you don’t search at import) and read from it whenever you need.Subscribing to events
The dispatcher emits a stream of typed actions. Subscribe to one by its type to run code whenever Discord fires it, then unsubscribe when your plugin stops.Common action types
Discord dispatches hundreds of action types. A few you’ll see often:Messages
Messages
MESSAGE_CREATE, MESSAGE_UPDATE, MESSAGE_DELETE, fired as messages come and go.Navigation
Navigation
Connection
Connection
CONNECTION_OPEN, fired once the client is connected and stores are populated. A good moment for setup that needs live state.