diff --git a/src/commands/utility/button.ts b/src/commands/utility/button.ts new file mode 100644 index 0000000..8397cba --- /dev/null +++ b/src/commands/utility/button.ts @@ -0,0 +1,30 @@ +import { ActionRowBuilder, ButtonBuilder, ButtonStyle, MessageFlags, SlashCommandBuilder } from "discord.js"; +import { CommandDefinition } from "../../type"; + +const cmd : CommandDefinition = { + data: new SlashCommandBuilder() + .setName('button') + .setDescription('Demo button'), + async execute(interaction) { + + const button = new ButtonBuilder() + .setCustomId('test-button') + .setLabel('Click me !') + .setStyle(ButtonStyle.Success); + + const row = new ActionRowBuilder() + .addComponents(button); + + await interaction.reply({content: 'Oh one button !', components: [row]}) + }, + buttons: [ + { + id: 'test-button', + async handle(interaction) { + await interaction.reply({content: 'Clicked !', flags: [MessageFlags.Ephemeral]}); + }, + } + ] +} + +export default cmd; \ No newline at end of file diff --git a/src/commands/utility/ping.ts b/src/commands/utility/ping.ts index 86f955b..c34e476 100644 --- a/src/commands/utility/ping.ts +++ b/src/commands/utility/ping.ts @@ -5,7 +5,7 @@ const cmd : CommandDefinition = { data: new SlashCommandBuilder() .setName('ping') .setDescription('Pong again!'), - async execute(interaction : ChatInputCommandInteraction) { + async execute(interaction) { await interaction.reply('Pong !'); } } diff --git a/src/type.d.ts b/src/type.d.ts index 9dd4278..3d13cb6 100644 --- a/src/type.d.ts +++ b/src/type.d.ts @@ -1 +1,3 @@ +import { ButtonInteraction, ChatInputCommandInteraction } from "discord.js"; + export type CommandDefinition = { data: SlashCommandBuilder, execute: (interaction: ChatInputCommandInteraction) => void, buttons?: { id: string, handle: (interaction: ButtonInteraction) => void}[]}; \ No newline at end of file