Extending Client and making Interaction.client use that new Client

As said in the guide, I have extended my Client class, no problems there. Though, I want to use interaction.client in my commands, yet that still refers to the old class. Forgive me, I'm a little new to JS and absolutely not sure how to go about this, am I thinking of it wrong even? Should I be passing client in my command handler? Should I just use imports? I would really like to avoid the imports, but I'm not against it. What is the right choice here, I'm almost positive I cannot be the first to ask this question, but a search yields no results here.
2 Replies
d.js toolkit
d.js toolkit9mo ago
- 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 OP
Haven
HavenOP9mo ago
Hold on, stupid discord index in these forums did not show a forum down like 8 posts... Honestly that was not helpful. Still need some help.
interface ExtendedClientOptions extends ClientOptions {
guildId?: string;
commandsDirectory?: string;
}

export class ExtendedClient extends Client {
commands: Collection<string, CommandType> = new Collection();
guildId?: string;
commandsDirectory: string = "";

constructor({
guildId,
commandsDirectory = "commands",
...options
}: ExtendedClientOptions) {
super(options);
this.guildId = guildId;
this.commandsDirectory = commandsDirectory;
}

...etc
}
interface ExtendedClientOptions extends ClientOptions {
guildId?: string;
commandsDirectory?: string;
}

export class ExtendedClient extends Client {
commands: Collection<string, CommandType> = new Collection();
guildId?: string;
commandsDirectory: string = "";

constructor({
guildId,
commandsDirectory = "commands",
...options
}: ExtendedClientOptions) {
super(options);
this.guildId = guildId;
this.commandsDirectory = commandsDirectory;
}

...etc
}
This is how I extended client. For future people: I'm going with the route of passing client to my commands in the handler, so instead of
function mycommand(interaction: CommandInteraction, arg1: string) ...
function mycommand(interaction: CommandInteraction, arg1: string) ...
I can do
function mycommand(client: ExtendedClient, interaction: CommandInteraction, arg1: string) ...
function mycommand(client: ExtendedClient, interaction: CommandInteraction, arg1: string) ...
Want results from more Discord servers?
Add your server