Skip to content

Commit 9c16888

Browse files
committed
feat: precondition can return promises
1 parent 9936f5a commit 9c16888

3 files changed

Lines changed: 9 additions & 7 deletions

File tree

playground/preconditions/ownerOnly.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { definePrecondition, useRuntimeEnv } from '../../src'
22

3-
export default definePrecondition((interaction) => {
3+
export default definePrecondition(async (interaction) => {
44
const env = useRuntimeEnv()
55
const authorId = interaction.member?.user.id
66

77
if (authorId && authorId !== env.ownerId) {
8-
interaction?.reply('You are not the owner of this bot!')
8+
await interaction.reply('You are not the owner of this bot!')
99
return false
1010
}
1111
return true

src/register.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ export const registerCommands = (harmonix: Harmonix) => {
6262
consola.warn(`Precondition \`${prc}\` not found.`)
6363
continue
6464
}
65-
const result = ctx.call(harmonix as RuntimeHarmonix, () =>
66-
precondition.callback(interaction)
65+
const result = await ctx.call(
66+
harmonix as RuntimeHarmonix,
67+
async () => await precondition.callback(interaction)
6768
)
6869

6970
if (!result) return
@@ -89,8 +90,9 @@ export const registerContextMenu = (harmonix: Harmonix) => {
8990
consola.warn(`Precondition \`${prc}\` not found.`)
9091
continue
9192
}
92-
const result = ctx.call(harmonix as RuntimeHarmonix, () =>
93-
precondition.callback(interaction)
93+
const result = await ctx.call(
94+
harmonix as RuntimeHarmonix,
95+
async () => await precondition.callback(interaction)
9496
)
9597

9698
if (!result) return

src/types/preconditions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export type PreconditionCallback<
1212
interaction: T extends 'ChatInput'
1313
? ChatInputCommandInteraction
1414
: MessageContextMenuCommandInteraction | UserContextMenuCommandInteraction
15-
) => boolean | void
15+
) => Promise<boolean> | Promise<void> | boolean | void
1616

1717
export interface DefinePrecondition {
1818
<T extends PreconditionType>(

0 commit comments

Comments
 (0)