So I was creating a Discord bot with the Discord.js library and Typescript, but I can't figure out why the class that I extended is working on the eslint, but not in the compiler.
This is where I create the client object.
const client = new Discord.Client({
intents: [
"GUILDS",
"GUILD_MESSAGES",
"GUILD_MEMBERS"
]
});
Which has the class Client, that don't have these properties:
client.commands = new Discord.Collection();
client.events = new Discord.Collection();
client.loadEvents = (botObject: typeof bot, reload: boolean) => require("./handlers/events")(botObject, reload);
client.loadEvents(bot, false);
So I created a discord.d.ts file at the root of the project on /types/common/discord.d.ts extending the class from Discord.js
import { Collection } from "discord.js";
import bot from "../../src/index";
declare module "discord.js" {
export interface Client {
commands: Collection<unknown, any>;
events: Collection<unknown, any>;
loadEvents: (botObject: typeof bot, reload: boolean) => any;
}
}
But it only works for the eslint, when I try to compile the bot it gives me the following error:
TSError: ⨯ Unable to compile TypeScript:
src/index.ts:39:8 - error TS2339: Property 'commands' does not exist on type 'Client<boolean>'.
39 client.commands = new Discord.Collection();
~~~~~~~~
src/index.ts:40:8 - error TS2339: Property 'events' does not exist on type 'Client<boolean>'.
40 client.events = new Discord.Collection();
~~~~~~
src/index.ts:42:8 - error TS2339: Property 'loadEvents' does not exist on type 'Client<boolean>'.
42 client.loadEvents = (botObject: typeof bot, reload: boolean) => require("./handlers/events")(botObject, reload);
~~~~~~~~~~
src/index.ts:44:8 - error TS2339: Property 'loadEvents' does not exist on type 'Client<boolean>'.
44 client.loadEvents(bot, false);
Can anyone please tell me what I'm missing here.