This commit is contained in:
MARCROCK22 2024-03-16 21:24:28 -04:00
parent e734b8d831
commit 6d4e0589b1
4 changed files with 9 additions and 7 deletions

View File

@ -81,7 +81,7 @@ export async function onInteractionCreate(
// idc, is a YOU problem // idc, is a YOU problem
if (!command?.run) if (!command?.run)
return self.logger.warn(`${command.name ?? 'Unknown'} command does not have 'run' callback`); return self.logger.warn(`${command.name ?? 'Unknown'} command does not have 'run' callback`);
const context = new MenuCommandContext(self, interaction, shardId); const context = new MenuCommandContext(self, interaction, shardId, command);
const extendContext = self.options?.context?.(interaction) ?? {}; const extendContext = self.options?.context?.(interaction) ?? {};
Object.assign(context, extendContext); Object.assign(context, extendContext);
try { try {
@ -145,7 +145,7 @@ export async function onInteractionCreate(
const command = optionsResolver.getCommand(); const command = optionsResolver.getCommand();
if (!command?.run) if (!command?.run)
return self.logger.warn(`${optionsResolver.fullCommandName} command does not have 'run' callback`); return self.logger.warn(`${optionsResolver.fullCommandName} command does not have 'run' callback`);
const context = new CommandContext(self, interaction, optionsResolver, shardId); const context = new CommandContext(self, interaction, optionsResolver, shardId, command);
const extendContext = self.options?.context?.(interaction) ?? {}; const extendContext = self.options?.context?.(interaction) ?? {};
Object.assign(context, extendContext); Object.assign(context, extendContext);
try { try {

View File

@ -96,7 +96,7 @@ export async function onMessageCreate(
const args = (self.options?.commands?.argsParser ?? defaultArgsParser)(content, command); const args = (self.options?.commands?.argsParser ?? defaultArgsParser)(content, command);
const { options, errors } = await parseOptions(self, command, rawMessage, args, resolved); const { options, errors } = await parseOptions(self, command, rawMessage, args, resolved);
const optionsResolver = new OptionResolver(self, options, parent as Command, message.guildId, resolved); const optionsResolver = new OptionResolver(self, options, parent as Command, message.guildId, resolved);
const context = new CommandContext(self, message, optionsResolver, shardId); const context = new CommandContext(self, message, optionsResolver, shardId, command);
try { try {
if (command.botPermissions && message.guildId) { if (command.botPermissions && message.guildId) {
const meMember = await self.cache.members?.get(self.botId, message.guildId); const meMember = await self.cache.members?.get(self.botId, message.guildId);

View File

@ -20,7 +20,7 @@ import {
} from '../../structures'; } from '../../structures';
import type { RegisteredMiddlewares } from '../decorators'; import type { RegisteredMiddlewares } from '../decorators';
import type { OptionResolver } from '../optionresolver'; import type { OptionResolver } from '../optionresolver';
import type { ContextOptions, OptionsRecord } from './chat'; import type { Command, ContextOptions, OptionsRecord, SubCommand } from './chat';
import type { CommandMetadata, ExtendContext, GlobalMetadata, UsingClient } from './shared'; import type { CommandMetadata, ExtendContext, GlobalMetadata, UsingClient } from './shared';
export interface CommandContext<T extends OptionsRecord = {}, M extends keyof RegisteredMiddlewares = never> export interface CommandContext<T extends OptionsRecord = {}, M extends keyof RegisteredMiddlewares = never>
@ -33,9 +33,10 @@ export class CommandContext<T extends OptionsRecord = {}, M extends keyof Regist
messageResponse?: If<InferWithPrefix, Message | undefined>; messageResponse?: If<InferWithPrefix, Message | undefined>;
constructor( constructor(
readonly client: UsingClient, readonly client: UsingClient,
data: ChatInputCommandInteraction | Message, readonly data: ChatInputCommandInteraction | Message,
public resolver: OptionResolver, readonly resolver: OptionResolver,
readonly shardId: number, readonly shardId: number,
readonly command: Command | SubCommand,
) { ) {
if (data instanceof Message) { if (data instanceof Message) {
this.message = data as never; this.message = data as never;

View File

@ -1,4 +1,4 @@
import { CommandContext, type ReturnCache, type WebhookMessage } from '../..'; import { CommandContext, type ContextMenuCommand, type ReturnCache, type WebhookMessage } from '../..';
import { import {
ApplicationCommandType, ApplicationCommandType,
MessageFlags, MessageFlags,
@ -35,6 +35,7 @@ export class MenuCommandContext<
readonly client: UsingClient, readonly client: UsingClient,
readonly interaction: T, readonly interaction: T,
readonly shardId: number, readonly shardId: number,
readonly command: ContextMenuCommand,
) {} ) {}
metadata: CommandMetadata<UnionToTuple<M>> = {} as never; metadata: CommandMetadata<UnionToTuple<M>> = {} as never;