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.
The theme is the binding call's whole theme, its server's and user's themes included, so every later call, whoever it is for, is answered in the starting member's theme.
Parameters
| Name | Type |
|---|---|
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 starting member's theme, @UseTheme included
await click.reply(`${emojis.success} Picked`)
}))
}