✨ Finalisation Command Handler + Ajout commande ping
This commit is contained in:
parent
a9b91137a1
commit
e95074ec29
@ -11,7 +11,7 @@ export class Command implements ICommand {
|
||||
category: Category;
|
||||
options: object;
|
||||
default_member_permissions: bigint;
|
||||
dm_permissions: boolean;
|
||||
dm_permission: boolean;
|
||||
cooldown: number;
|
||||
|
||||
constructor(client: CustomClient, options: ICommandOptions) {
|
||||
@ -21,7 +21,7 @@ export class Command implements ICommand {
|
||||
this.category = options.category;
|
||||
this.options = options.options;
|
||||
this.default_member_permissions = options.default_member_permissions;
|
||||
this.dm_permissions = options.dm_permissions;
|
||||
this.dm_permission = options.dm_permission;
|
||||
this.cooldown = options.cooldown;
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@ export interface ICommand {
|
||||
category: Category;
|
||||
options: object;
|
||||
default_member_permissions: bigint;
|
||||
dm_permissions: boolean;
|
||||
dm_permission: boolean;
|
||||
cooldown: number;
|
||||
|
||||
execute(interaction: ChatInputCommandInteraction): void;
|
||||
|
@ -6,6 +6,6 @@ export interface ICommandOptions {
|
||||
category: Category;
|
||||
options: object;
|
||||
default_member_permissions: bigint;
|
||||
dm_permissions: boolean;
|
||||
dm_permission: boolean;
|
||||
cooldown: number;
|
||||
}
|
25
src/commands/PingCommand.ts
Normal file
25
src/commands/PingCommand.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import {Command} from "../base/classes/Command";
|
||||
import {CustomClient} from "../base/classes/CustomClient";
|
||||
import {Category} from "../base/enums/Category";
|
||||
import {PermissionsBitField} from "discord.js";
|
||||
|
||||
export class PingCommand extends Command {
|
||||
constructor(client: CustomClient) {
|
||||
super(client, {
|
||||
name: 'ping',
|
||||
description: ' Pong!',
|
||||
category: Category.UTILITIES,
|
||||
options: [],
|
||||
default_member_permissions: PermissionsBitField.Flags.UseApplicationCommands,
|
||||
dm_permission: true,
|
||||
cooldown: 5
|
||||
});
|
||||
}
|
||||
|
||||
execute(interaction: any): void {
|
||||
interaction.reply({
|
||||
content: `Pong!`,
|
||||
ephemeral: true
|
||||
});
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
import {Event} from '../../base/classes/Event';
|
||||
import {CustomClient} from "../../base/classes/CustomClient";
|
||||
import {Events} from "discord.js";
|
||||
import {Collection, Events, REST, Routes} from "discord.js";
|
||||
import {Command} from "../../base/classes/Command";
|
||||
export class Ready extends Event {
|
||||
constructor(client: CustomClient) {
|
||||
super(client, {
|
||||
@ -10,7 +11,38 @@ export class Ready extends Event {
|
||||
});
|
||||
}
|
||||
|
||||
execute(...args: any[]): void {
|
||||
async execute(...args: any[]): Promise<void> {
|
||||
console.log(`Connecté en tant que ${this.client.user?.tag}!`);
|
||||
|
||||
const commands: object[] = this.getJson(this.client.commands);
|
||||
|
||||
const rest = new REST({version: '10'}).setToken(this.client.config.token);
|
||||
|
||||
const setCommands: any = await rest.put(
|
||||
Routes.applicationCommands(this.client.user?.id!),
|
||||
{
|
||||
body: commands
|
||||
}
|
||||
);
|
||||
|
||||
console.log(`${setCommands.length} Commandes mises à jours avec succès !`);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private getJson(commands: Collection<string, Command>): object[] {
|
||||
const data: object[] = [];
|
||||
|
||||
commands.forEach((command: Command) => {
|
||||
data.push({
|
||||
name: command.name,
|
||||
description: command.description,
|
||||
options: command.options,
|
||||
default_member_permissions: command.default_member_permissions.toString(),
|
||||
dm_permission: command.dm_permission,
|
||||
})
|
||||
});
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
@ -33,12 +33,24 @@ export class CommandHandler extends Event {
|
||||
const cooldownAmount = (command.cooldown || 3) * 1000;
|
||||
|
||||
if (timestamps.has(interaction.user.id) && now < (timestamps.get(interaction.user.id) || 0) + cooldownAmount) {
|
||||
const timeLeft = (((timestamps.get(interaction.user.id) || 0) + cooldownAmount - now) / 1000).toFixed(1);
|
||||
await interaction.reply({
|
||||
content: `Veuillez patienter ${((timestamps.get(interaction.user.id) || 0) + cooldownAmount - now) / 1000} secondes avant de réutiliser la commande \`${command.name}\``
|
||||
})
|
||||
content: `Veuillez patienter ${timeLeft} secondes avant de réutiliser la commande \`${command.name}\``,
|
||||
ephemeral: true
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
timestamps.set(interaction.user.id, now);
|
||||
setTimeout(() => timestamps.delete(interaction.user.id), cooldownAmount);
|
||||
|
||||
command.execute(interaction);
|
||||
try {
|
||||
const subCommandGroup = interaction.options.getSubcommandGroup(false);
|
||||
const subCommand = `${interaction.commandName}${subCommandGroup ? `.${subCommandGroup}` : ''}.${interaction.options.getSubcommand(false)}` || '';
|
||||
|
||||
this.client.subCommands.get(subCommand)?.execute(interaction) || command.execute(interaction);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user