export class ExtendedClient extends Client {
commands: Collection<string, CommandType> = new Collection();
constructor() {
super({ intents: 32767 });
}
start(){
this.RegisterModules()
this.login(process.env.BotToken)
}
async ImportFile(FilePath: string){
return (await import(FilePath))?.default;
}
async RegisterCommands( {Commands, GuildId: GuildID}: RegisterCommandOptions){
if (GuildID){
this.guilds.cache.get(GuildID)?.commands.set(Commands);
console.log(`Registered ${Commands.length} commands in guild ${GuildID}`);
}else{
this.application?.commands.set(Commands);
console.log(`Registered ${Commands.length} global commands`);
}
}
async RegisterModules(){
const slashCommands: ApplicationCommandDataResolvable[] = [];
const commandFiles = await globPromise(
`${__dirname}/../Commands/*/*{.ts,.js}`
);
commandFiles.forEach(async (filePath) => {
const command: CommandType = await this.ImportFile(filePath);
if (!command.name) return;
console.log(command);
this.commands.set(command.name, command);
slashCommands.push(command);
});
this.on("ready", () => {
this.RegisterCommands({
Commands: slashCommands,
GuildId: process.env.GuildId
});
server.CheckSentInvoices()
});
const EventFiles = await globPromise(
`${__dirname}/../events/*{.ts,.js}`
);
EventFiles.forEach(async (filePath) => {
const event: Event<keyof ClientEvents> = await this.ImportFile(
filePath
);
this.on(event.event, event.run);
});
}
}