fix custom context in prefix commands (#159)

This commit is contained in:
JustEvil 2024-03-18 15:40:56 -06:00 committed by GitHub
parent 74159ac1da
commit c1351f32de
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 12 deletions

View File

@ -27,7 +27,7 @@ import {
import type { DeepPartial, IntentStrings, OmitInsert } from '../common/types/util';
import { ComponentHandler } from '../components/handler';
import { LangsHandler } from '../langs/handler';
import type { ChatInputCommandInteraction, MessageCommandInteraction, UserCommandInteraction } from '../structures';
import type { ChatInputCommandInteraction, Message, MessageCommandInteraction, UserCommandInteraction } from '../structures';
export class BaseClient {
rest!: ApiHandler;
@ -245,7 +245,8 @@ export interface BaseClientOptions {
interaction:
| ChatInputCommandInteraction<boolean>
| UserCommandInteraction<boolean>
| MessageCommandInteraction<boolean>,
| MessageCommandInteraction<boolean>
| Message
) => {};
globalMiddlewares?: readonly (keyof RegisteredMiddlewares)[];
}

View File

@ -97,6 +97,8 @@ export async function onMessageCreate(
const { options, errors } = await parseOptions(self, command, rawMessage, args, resolved);
const optionsResolver = new OptionResolver(self, options, parent as Command, message.guildId, resolved);
const context = new CommandContext(self, message, optionsResolver, shardId, command);
const extendContext = self.options?.context?.(message) ?? {};
Object.assign(context, extendContext);
try {
if (command.botPermissions && message.guildId) {
const meMember = await self.cache.members?.get(self.botId, message.guildId);

View File

@ -1,7 +1,7 @@
import type { InternalRuntimeConfig, InternalRuntimeConfigHTTP, RuntimeConfig, RuntimeConfigHTTP } from './client/base';
import { GatewayIntentBits } from './common';
import type { ClientNameEvents, EventContext } from './events';
import type { ChatInputCommandInteraction, MessageCommandInteraction, UserCommandInteraction } from './structures';
import type { ChatInputCommandInteraction, Message, MessageCommandInteraction, UserCommandInteraction } from './structures';
export { Logger, PermissionFlagsBits, PermissionStrings, Watcher } from './common';
//
@ -95,7 +95,7 @@ export const config = {
* });
*/
export function extendContext<T extends {}>(
cb: (interaction: ChatInputCommandInteraction | UserCommandInteraction | MessageCommandInteraction) => T,
cb: (interaction: ChatInputCommandInteraction | UserCommandInteraction | MessageCommandInteraction | Message) => T,
) {
return cb;
}