#Building slash command in module differently
14 messages · Page 1 of 1 (latest)
It's possible in TS, but you should make your own type for the command files (referencing DJS' ApplicationCommandData interface is a good place to start
If you're having a specific error in TS that you're not sure how to get around, feel free to share that too
U mean the thing about attaching .commands to the client ?
If so, it would look something like that ?
export interface IDiscordClient {
commands: Collection<string, ApplicationCommandData>;
}
export default class DiscordClient extends Client implements IDiscordClient {
public commands: Collection<string, ApplicationCommandData>;
constructor(options: ClientOptions) {
super(options);
this.commands = new Collection();
}
}
Wait no, making a new class impementing the ApplicationCommandData seems like more appropriate
ApplicationCommand (extends Base)
Represents an application command.
In your command files, the best way to enforce your custom command type would be const command: YourInterfaceHere = {...} and then export default command;
Or ts export default {....} satisfies CommandInterfaceThat's how i do it
Ah smart, I haven't looked too much into satisfies yet
satisfies is the perfect fit in this scenario
I've never used satisfies, nor even seen it, i'm not sure how to make it work
I tried creating an interface like this :
export interface ICommands extends ApplicationCommandData{
category: string;
permissions: bigint[];
usage: string;
examples: string[];
}
But VSCode throws this
An interface can only extend an object type or intersection of object types with statically known members.ts(2312)
Its a new keyword added in v4.9
https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-9.html
TypeScript 4.9 Release Notes
You can only extend interface from another interface or class. But ApplicationCommandData is a union type