super.user error after updating packages
Code
Error:
import { Client as BaseClient, ClientUser, Collection, GatewayIntentBits } from "discord.js";
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;
import { Client as BaseClient, ClientUser, Collection, GatewayIntentBits } from "discord.js";
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;
src/structures/Client.ts:26:23 - error TS2855: Class field 'user' defined by the parent class is not accessible in the child class via super.
26 this.user = super.user as ClientUser;
~~~~
Found 1 error in src/structures/Client.ts:26
src/structures/Client.ts:26:23 - error TS2855: Class field 'user' defined by the parent class is not accessible in the child class via super.
26 this.user = super.user as ClientUser;
~~~~
Found 1 error in src/structures/Client.ts:26
2 Replies
- What's your exact discord.js
npm list discord.js
and node node -v
version?
- Not a discord.js issue? Check out #other-js-ts.
- 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 OPSorry
This isnt a djs problem
I think
One of the other devs did it
I dont know how to rewrite it
Im new to typescript
So if I remove super
The intents still stay
'client.user' is possibly 'null'.
This appeared
In all of my files
Could you tell me how please.
Well the problem is
The code is 4 months old
He left discord
I tried fix this for many hours
But cant find any solutions
the code is private ill give u all the code
Does this help?
Ill remove the client interface
Could you tell me a bit more clearly
this is Client<true>?
The return type of an async function or method must be the global Promise<T> type. Did you mean to write 'Promise<boolean>'?ts(1064)
Argument of type 'this' is not assignable to parameter of type 'Client'.ts(2345)
This is the error
In handlers
I didnt get where u wanted me to put the client sorry
Still getting an error
With "this"
in the handlers
Argument of type 'this' is not assignable to parameter of type 'Client'.ts(2345)
Ok
import { Client as BaseClient, ClientUser, Collection, GatewayIntentBits } from "discord.js";
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;
import { Client as BaseClient, ClientUser, Collection, GatewayIntentBits } from "discord.js";
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;
import { Client as BaseClient, ClientUser, Collection } from "discord.js";
import Command from "./Command.js";
import ClientConfig from "./ClientConfig.js";
import Modal from "./Modal.js";
import { PasteClient } from "pastebin-api";
interface Client extends BaseClient {
readonly commands: Collection<string, Command>;
readonly modals: Collection<string, Modal>;
config: ClientConfig;
pastebin: PasteClient;
user: ClientUser
init: () => Promise<void>;
}
export default Client;
import { Client as BaseClient, ClientUser, Collection } from "discord.js";
import Command from "./Command.js";
import ClientConfig from "./ClientConfig.js";
import Modal from "./Modal.js";
import { PasteClient } from "pastebin-api";
interface Client extends BaseClient {
readonly commands: Collection<string, Command>;
readonly modals: Collection<string, Modal>;
config: ClientConfig;
pastebin: PasteClient;
user: ClientUser
init: () => Promise<void>;
}
export default Client;
import Client from "./structures/Client.js";
const client = new Client();
client.init();
export default client;
import Client from "./structures/Client.js";
const client = new Client();
client.init();
export default client;
import { Client as BaseClient, Collection, GatewayIntentBits } from "discord.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<T extends boolean> extends BaseClient<T> {
public readonly commands: Collection<string, Command>;
public readonly modals: Collection<string, Modal>;
public pastebin: PasteClient;
constructor() {
super({
intents: [GatewayIntentBits.Guilds],
allowedMentions: { parse: ["users"] },
});
this.commands = new Collection<string, Command>();
this.modals = new Collection<string, Modal>();
this.pastebin = new PasteClient(this.config.pastebin);
}
config = secrets as unknown as ClientConfig;
async init() {
await sendLog(`[SYSTEM] Handlers have been initiated.`);
const client = await new Client().init();
await CommandHandler(this);
await EventHandler(this);
await ModalHandler(this);
return await this.login(this.config.token);
}
}
export default Client;
import { Client as BaseClient, Collection, GatewayIntentBits } from "discord.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<T extends boolean> extends BaseClient<T> {
public readonly commands: Collection<string, Command>;
public readonly modals: Collection<string, Modal>;
public pastebin: PasteClient;
constructor() {
super({
intents: [GatewayIntentBits.Guilds],
allowedMentions: { parse: ["users"] },
});
this.commands = new Collection<string, Command>();
this.modals = new Collection<string, Modal>();
this.pastebin = new PasteClient(this.config.pastebin);
}
config = secrets as unknown as ClientConfig;
async init() {
await sendLog(`[SYSTEM] Handlers have been initiated.`);
const client = await new Client().init();
await CommandHandler(this);
await EventHandler(this);
await ModalHandler(this);
return await this.login(this.config.token);
}
}
export default Client;
import { Client as BaseClient, Collection, GatewayIntentBits } from "discord.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<true> {
public readonly commands: Collection<string, Command>;
public readonly modals: Collection<string, Modal>;
public pastebin: PasteClient;
constructor() {
super({
intents: [GatewayIntentBits.Guilds],
allowedMentions: { parse: ["users"] },
});
this.commands = new Collection<string, Command>();
this.modals = new Collection<string, Modal>();
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);
return await this.login(this.config.token);
}
}
export default Client;
import { Client as BaseClient, Collection, GatewayIntentBits } from "discord.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<true> {
public readonly commands: Collection<string, Command>;
public readonly modals: Collection<string, Modal>;
public pastebin: PasteClient;
constructor() {
super({
intents: [GatewayIntentBits.Guilds],
allowedMentions: { parse: ["users"] },
});
this.commands = new Collection<string, Command>();
this.modals = new Collection<string, Modal>();
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);
return await this.login(this.config.token);
}
}
export default Client;
import fs from "fs";
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;
import fs from "fs";
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;