Skip to content

Commit a52ad27

Browse files
authored
fix: context-interactions error (#382)
1 parent 3f703c1 commit a52ad27

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

Diff for: src/core/functions.ts

+3
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ export function isMessageComponent(i: InteractionTypable): i is AnyMessageCompon
119119
export function isCommand(i: InteractionTypable): i is AnyCommandInteraction {
120120
return i.type === InteractionType.ApplicationCommand;
121121
}
122+
export function isContextCommand(i: AnyCommandInteraction): i is MessageContextMenuCommandInteraction | UserContextMenuCommandInteraction {
123+
return i.isContextMenuCommand();
124+
}
122125
export function isAutocomplete(i: InteractionTypable): i is AutocompleteInteraction {
123126
return i.type === InteractionType.ApplicationCommandAutocomplete;
124127
}

Diff for: src/handlers/interaction.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Module } from '../types/core-modules'
22
import { callPlugins, executeModule } from './event-utils';
33
import { SernError } from '../core/structures/enums'
4-
import { createSDT, isAutocomplete, isCommand, isMessageComponent, isModal, resultPayload, treeSearch } from '../core/functions'
4+
import { createSDT, isAutocomplete, isCommand, isContextCommand, isMessageComponent, isModal, resultPayload, treeSearch } from '../core/functions'
55
import type { UnpackedDependencies } from '../types/utility';
66
import * as Id from '../core/id'
77
import { Context } from '../core/structures/context';
@@ -29,13 +29,23 @@ export function interactionHandler(deps: UnpackedDependencies, defaultPrefix?: s
2929
}
3030
const { module, params } = modules.at(0)!;
3131
let payload;
32+
// handles autocomplete
3233
if(isAutocomplete(event)) {
3334
//@ts-ignore stfu
3435
const { command } = treeSearch(event, module.options);
3536
payload= { module: command as Module, //autocomplete is not a true "module" warning cast!
3637
args: [event, createSDT(command, deps, params)] };
38+
// either CommandTypes Slash | ContextMessage | ContextUesr
3739
} else if(isCommand(event)) {
38-
payload= { module, args: [Context.wrap(event, defaultPrefix), createSDT(module, deps, params)] };
40+
const sdt = createSDT(module, deps, params)
41+
// handle CommandType.CtxUser || CommandType.CtxMsg
42+
if(isContextCommand(event)) {
43+
payload= { module, args: [event, sdt] };
44+
} else {
45+
// handle CommandType.Slash || CommandType.Both
46+
payload= { module, args: [Context.wrap(event, defaultPrefix), sdt] };
47+
}
48+
// handles modals or components
3949
} else if (isModal(event) || isMessageComponent(event)) {
4050
payload= { module, args: [event, createSDT(module, deps, params)] }
4151
} else {

0 commit comments

Comments
 (0)