starting to add slash commands

This commit is contained in:
Jaron Pate
2022-09-20 19:32:41 -05:00
parent a346d56f9b
commit 230aee97fa
10 changed files with 276 additions and 47 deletions
+27 -2
View File
@@ -1,6 +1,6 @@
import { ComponentStyle, Context, Gateway, Guilds, Message } from './lib';
import { ComponentStyle, Context, Gateway, Guilds, Message, Embed } from './lib';
import { Command, CommandFuntion, Intent, Presence } from './types';
export { ComponentStyle, Context, Gateway, Guilds, Message, Command, CommandFuntion, Intent, Presence };
export { ComponentStyle, Context, Gateway, Guilds, Message, Embed, Command, CommandFuntion, Intent, Presence };
type Config = {
token: string;
@@ -15,6 +15,7 @@ export class Client {
readonly application_id: string;
private readonly gateway: Gateway;
private readonly client_commands: Map<string, Command | CommandFuntion> = new Map();
private readonly slash_commands: Map<string, Command | CommandFuntion> = new Map();
readonly guilds: Guilds;
constructor({ token, application_id, prefix, intents }: Config) {
@@ -23,6 +24,8 @@ export class Client {
this.prefix = prefix ?? '!';
this.gateway = new Gateway({ token, intents, client: this });
this.guilds = new Guilds({ token, gateway: this.gateway });
// Do some default stuff
this.initialize();
}
get user() {
@@ -84,6 +87,28 @@ export class Client {
},
delete: (command_name: string) => {
this.client_commands.delete(command_name);
},
list: () => {
return this.client_commands;
}
};
private initialize = () => {
// Register default help command
this.commands.register('help', (client, context, _args) => {
const embed = new Embed().setTitle('Commands').setDescription('This is a list of commands you can use.');
const commands = Array.from(client.commands.list().entries());
for (const [name, command] of commands) {
embed.addField({
name: name,
value: command instanceof Command ? command.description : 'No description provided'
});
}
context.reply(embed.toMessage());
});
}
}