#super.user() error

30 messages · Page 1 of 1 (latest)

broken saffron
#
import Client from "../Interfaces/Client.js";
import Command from "../Interfaces/Command.js";
import sendLog from "../functions/sendLog.js";
function CommandHandler(client: Client): void {
  fs.readdirSync("./build/commands").forEach(async dir => {
    const commands = fs.readdirSync(`./build/commands/${dir}`).filter(file => file.endsWith(".js"));

    for (const file of commands) {
      const command: Command = await import(`../commands/${dir}/${file}`).then(
        imported => imported.default
      );

      client.commands.set(command.data.name, command);
      const handlerMessage = `[HANDLER - COMMAND] Loaded a command: ${file} (#${client.commands.size})`;
      sendLog(handlerMessage, 2);
    }
  });
}

export default CommandHandler;
tribal harborBOT
#
  • 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
broken saffron
#

client was defined by (this)

topaz jasper
#

Okay, you might need to actually implement that interface again, since your code seems to rely on it

broken saffron
#

so we could do client.user

#

client .commands

broken saffron
#

The super.user was so client.user could be used to mention bot properties

#

I need a way to add client.user without using super.user

topaz jasper
#

But client.user already is a ClientUser per default. And your extends Client<true> should give you exactly what you want

#

Your interface might need to extend BaseClient<true> too though

#

And remove the user property from it

broken saffron
#

Original code:

import IClient from "../Interfaces/Client.js";
import Command from "../Interfaces/Command.js";
import ClientConfig from "../Interfaces/ClientConfig.js";
import CommandHandler from "../handlers/commandHandler.js";
import EventHandler from "../handlers/eventHandler.js";
import Modal from "../Interfaces/Modal.js";
import ModalHandler from "../handlers/modalHandler.js";
import { PasteClient } from "pastebin-api";
import secrets from "../json/secrets.json" assert { type: "json" };
import sendLog from "../functions/sendLog.js";
class Client extends BaseClient implements IClient {
  public readonly commands: Collection<string, Command>;
  public readonly modals: Collection<string, Modal>;
  public user: ClientUser;
  public pastebin: PasteClient;
  constructor() {
    super({
      intents: [GatewayIntentBits.Guilds],
      allowedMentions: { parse: ["users"] },
    });

    this.commands = new Collection<string, Command>();
    this.modals = new Collection<string, Modal>();
    this.user = super.user as ClientUser;
    this.pastebin = new PasteClient(this.config.pastebin);
  }
  config = secrets as unknown as ClientConfig;
  async init() {
    await sendLog(`[SYSTEM] Handlers have been initiated.`);
    await CommandHandler(this);
    await EventHandler(this);
    await ModalHandler(this);
    await this.login(this.config.token);
  }
}

export default Client;
topaz jasper
#

BaseClient<true> (ah, original code, mb)

#

Remove public user… and this.user =… lines, add the <true> and same for the interface

broken saffron
#

adding true gives more errors

topaz jasper
#

What errors?

broken saffron
#

src/events/interactionCreate/interactionCreate.ts:33:25 - error TS2345: Argument of type 'import("S:/Ahmad/Entertainment/Projects/Repositories/AkiraBot/src/Interfaces/Client").default' is not assignable to parameter of type 'import("S:/Ahmad/Entertainment/Projects/Repositories/AkiraBot/src/structures/Client").default'.

33 await command.run(client, interaction);
~~~~~~

src/events/interactionCreate/modal.ts:17:30 - error TS2345: Argument of type 'import("S:/Ahmad/Entertainment/Projects/Repositories/AkiraBot/src/Interfaces/Client").default' is not assignable to parameter of type 'import("S:/Ahmad/Entertainment/Projects/Repositories/AkiraBot/src/structures/Client").default'.

17 await modalCommand.run(client, interaction);
~~~~~~

src/structures/Client.ts:25:23 - error TS2855: Class field 'user' defined by the parent class is not accessible in the child class via super.

25 this.user = super.user as ClientUser;
~~~~

src/structures/Event.ts:7:10 - error TS2416: Property 'run' in type 'Event<K>' is not assignable to the same property in base type 'Event<K>'.
Type '(client: Client, ...args: ClientEvents[K]) => unknown' is not assignable to type '(client: Client, ...args: ClientEvents[K]) => any'.
Types of parameters 'client' and 'client' are incompatible.
Type 'import("S:/Ahmad/Entertainment/Projects/Repositories/AkiraBot/src/Interfaces/Client").default' is not assignable to type 'import("S:/Ahmad/Entertainment/Projects/Repositories/AkiraBot/src/structures/Client").default'.
Types of property '_ready' are incompatible.
Type 'boolean' is not assignable to type 'true'.

#

7 public run: (client: Client, ...args: ClientEvents[K]) => unknown;
~~~

Found 4 errors in 4 files.

Errors Files
1 src/events/interactionCreate/interactionCreate.ts:33
1 src/events/interactionCreate/modal.ts:17
1 src/structures/Client.ts:25
1 src/structures/Event.ts:7

#

Without true its only

src/structures/Client.ts:25:23 - error TS2855: Class field 'user' defined by the parent class is not accessible in the child class via super.

25 this.user = super.user as ClientUser;
~~~~

Found 1 error in src/structures/Client.ts:25

topaz jasper
#

Of those „new“ errors only the last one would be present if you did all the changes I said

broken saffron
#

Ok

#

doing

#

Wow

topaz jasper
#

Not even the last one should be

broken saffron
#

IT WORKED

#

Thanks so much

#

!

#

I owe you everything

#

I tried for so long