Skip to content

Commit 5c35735

Browse files
committed
feat: add the possibility to specify if context menu is message or user in the type
1 parent ebb9e0d commit 5c35735

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

src/define.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,26 @@ export const defineCommand = <
7070
}
7171

7272
export const defineContextMenu: DefineContextMenu &
73-
DefineContextMenuWithOptions = (
74-
...args: [ContextMenuOptions | ContextMenuCallback, ContextMenuCallback?]
73+
DefineContextMenuWithOptions = <Type extends 'message' | 'user'>(
74+
...args: [
75+
ContextMenuOptions | ContextMenuCallback<Type>,
76+
ContextMenuCallback<Type>?
77+
]
7578
): HarmonixContextMenu => {
7679
let options: ContextMenuOptions = {}
7780

7881
if (args.length === 1) {
79-
const [callback] = args as [ContextMenuCallback]
82+
const [callback] = args as [ContextMenuCallback<Type>]
8083

8184
return {
8285
options,
8386
callback
8487
}
8588
} else {
86-
const [opts, callback] = args as [ContextMenuOptions, ContextMenuCallback]
89+
const [opts, callback] = args as [
90+
ContextMenuOptions,
91+
ContextMenuCallback<Type>
92+
]
8793

8894
options = opts
8995
return {

src/types/contextMenus.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import type {
2-
CacheType,
32
MessageContextMenuCommandInteraction,
43
PermissionsString,
54
UserContextMenuCommandInteraction
65
} from 'discord.js'
76

8-
export type ContextMenuCallback = (
9-
interaction:
10-
| MessageContextMenuCommandInteraction<CacheType>
11-
| UserContextMenuCommandInteraction<CacheType>
7+
export type ContextMenuCallback<Type extends 'message' | 'user'> = (
8+
interaction: Type extends 'message'
9+
? MessageContextMenuCommandInteraction
10+
: UserContextMenuCommandInteraction
1211
) => void
1312

1413
export interface ContextMenuOptions {
@@ -18,17 +17,17 @@ export interface ContextMenuOptions {
1817
preconditions?: string[]
1918
}
2019

21-
export type DefineContextMenu = (
22-
callback: ContextMenuCallback
20+
export type DefineContextMenu = <Type extends 'message' | 'user'>(
21+
callback: ContextMenuCallback<Type>
2322
) => HarmonixContextMenu
24-
export type DefineContextMenuWithOptions = (
23+
export type DefineContextMenuWithOptions = <Type extends 'message' | 'user'>(
2524
options: ContextMenuOptions,
26-
callback: ContextMenuCallback
25+
callback: ContextMenuCallback<Type>
2726
) => HarmonixContextMenu
2827

2928
export type HarmonixContextMenuInput = string | HarmonixContextMenu
3029

3130
export interface HarmonixContextMenu {
3231
options: ContextMenuOptions
33-
callback: ContextMenuCallback
32+
callback: ContextMenuCallback<'message' | 'user'>
3433
}

0 commit comments

Comments
 (0)