#(some text) is not a function error. Decorators.

3 messages · Page 1 of 1 (latest)

left belfry

I'm getting this error

/Users/dhruv/Desktop/Discord/Luna Labs/Luna/source/Services/Application/ApplicationClear.ts:12
  @Confirmable('Are you sure you want to clear your application?')
              ^
TypeError: (0 , library_1.Confirmable) is not a function
    at Object.<anonymous> (/Users/dhruv/Desktop/Discord/Luna Labs/Luna/source/Services/Application/ApplicationClear.ts:12:15)
    at Module._compile (node:internal/modules/cjs/loader:1369:14)
    at Module.m._compile (/Users/dhruv/Desktop/Discord/Luna Labs/Luna/node_modules/.pnpm/ts-node@10.9.2_@types+node@20.14.15_typescript@5.5.4/node_modules/ts-node/src/index.ts:1618:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1427:10)
    at Object.require.extensions.<computed> [as .ts] (/Users/dhruv/Desktop/Discord/Luna Labs/Luna/node_modules/.pnpm/ts-node@10.9.2_@types+node@20.14.15_typescript@5.5.4/node_modules/ts-node/src/index.ts:1621:12)
    at Module.load (node:internal/modules/cjs/loader:1206:32)
    at Function.Module._load (node:internal/modules/cjs/loader:1022:12)
    at Module.require (node:internal/modules/cjs/loader:1231:19)
    at require (node:internal/modules/helpers:179:18)
    at Object.<anonymous> (/Users/dhruv/Desktop/Discord/Luna Labs/Luna/source/Handlers/ButtonHandler.ts:4:1)

Thing is, it wasn't happening before and I don't know what I changed to have it start to happen. Nothing shows up in the linter either.

The Decorator is exported and imported correctly but it throws this error.
Experimental decorators are also enabled in my tsconfig file.

Here's the usage and the decorator.

export class ApplicationClear extends Executable<ButtonInteraction> {
  constructor(interaction: ButtonInteraction) {
    super(interaction);
  }

  @Catchable()
  @Confirmable('Are you sure you want to clear your application?')
  public async execute(): Promise<void> {
    this.event.replied = true;
    await ApplicationCRUD.clearApplication(this.event.user.id);

    await new ApplicationForm(this.event).execute();
  }
}
export function Confirmable(text: string) {
  return function (
    _target: ExecutableInteraction,
    _propertyKey: string,
    descriptor: TypedPropertyDescriptor<(...args: any[]) => Promise<void>>
  ) {
    const originalMethod = descriptor.value;

    descriptor.value = async function (
      this: ExecutableInteraction,
      ...args: any[]
    ): Promise<void> {
      const interaction = this.event;

      if (!originalMethod) {
        throw new Error('Method not found');
      }

      if (!interaction.deferred) {
        interaction.isChatInputCommand()
          ? await interaction.deferReply()
          : await interaction.deferUpdate();
      }

      const confirmation = await interaction.followUp({
        ephemeral: true,
        embeds: [new ConfirmationEmbed(text).getComponent],
        components: [new ConfirmationRow().getComponent]
      });

      const response = await confirmation
        .awaitMessageComponent({
          componentType: ComponentType.Button,
          time: 10_000
        })
        .then((button) => {
          button.deferUpdate().catch(() => false);

          if (button.customId === 'confirm') {
            return true;
          } else {
            return false;
          }
        })
        .catch(() => false);

      await interaction.deleteReply(confirmation);

      if (response) {
        await originalMethod.apply(this, args);
      } else {
        return;
      }
    };

    return descriptor;
  };
}
late muskBOT
  • Consider reading #how-to-get-help to improve your question!
  • Explain what exactly your issue is.
  • Post the full error stack trace, not just the top part!
  • Show your code!
  • Issue solved? Press the button!
  • Marked as resolved by OP
left belfry

I removed all the index.ts files in my project and that fixed the error