1 Commits

3 changed files with 33 additions and 1 deletions

View File

@@ -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<ButtonBuilder>()
.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;

View File

@@ -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 !');
}
}

2
src/type.d.ts vendored
View File

@@ -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}[]};