bindTheme
function in meocord/common Since 4.1.0
bindTheme<F extends (...args: any[]) => unknown>(fn: F): FMakes a function run in the theme of the call that binds it, wherever it is called from later.
Wrap a listener a handler registers in it, such as a collector's collect callback or a client.on(...) handler.
Such a listener runs in its emitter's context, so without it a useTheme() inside reads the theme outside any call.
Timers and promises the handler starts keep its theme without it.
Parameters
| Name | Type | Description |
|---|---|---|
fn | F | The function to run in the call's theme; |
Returns
FA function that runs fn in the theme useTheme() returns where bindTheme is called.
Examples
@MessageHandler('poll')
async poll(message: Message) {
const collector = message.createMessageComponentCollector({ componentType: ComponentType.Button, time: 60_000 })
collector.on('collect', bindTheme(async (click: ButtonInteraction) => {
const { emojis } = useTheme() // the handler's theme, @UseTheme included
await click.reply(`${emojis.success} Picked`)
}))
}