diff --git a/src/client/base.ts b/src/client/base.ts index e948374..6363e86 100644 --- a/src/client/base.ts +++ b/src/client/base.ts @@ -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 | UserCommandInteraction - | MessageCommandInteraction, + | MessageCommandInteraction + | Message ) => {}; globalMiddlewares?: readonly (keyof RegisteredMiddlewares)[]; } diff --git a/src/client/onmessagecreate.ts b/src/client/onmessagecreate.ts index fc335a3..3a2f85a 100644 --- a/src/client/onmessagecreate.ts +++ b/src/client/onmessagecreate.ts @@ -44,15 +44,15 @@ function getCommandFromContent( const command = groupName || subcommandName ? (parent.options?.find(opt => { - if (opt instanceof SubCommand) { - if (groupName) { - if (opt.group !== groupName) return false; - } - if (opt.group && !groupName) return false; - return subcommandName === opt.name; + if (opt instanceof SubCommand) { + if (groupName) { + if (opt.group !== groupName) return false; } - return false; - }) as SubCommand) + if (opt.group && !groupName) return false; + return subcommandName === opt.name; + } + return false; + }) as SubCommand) : parent; return { @@ -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); diff --git a/src/index.ts b/src/index.ts index 77ac638..2caf22a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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( - cb: (interaction: ChatInputCommandInteraction | UserCommandInteraction | MessageCommandInteraction) => T, + cb: (interaction: ChatInputCommandInteraction | UserCommandInteraction | MessageCommandInteraction | Message) => T, ) { return cb; }