Refactor ping command to remove explicit type for interaction and add button command implementation
This commit is contained in:
30
src/commands/utility/button.ts
Normal file
30
src/commands/utility/button.ts
Normal 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;
|
||||||
@@ -5,7 +5,7 @@ const cmd : CommandDefinition = {
|
|||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
.setName('ping')
|
.setName('ping')
|
||||||
.setDescription('Pong again!'),
|
.setDescription('Pong again!'),
|
||||||
async execute(interaction : ChatInputCommandInteraction) {
|
async execute(interaction) {
|
||||||
await interaction.reply('Pong !');
|
await interaction.reply('Pong !');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
2
src/type.d.ts
vendored
2
src/type.d.ts
vendored
@@ -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}[]};
|
export type CommandDefinition = { data: SlashCommandBuilder, execute: (interaction: ChatInputCommandInteraction) => void, buttons?: { id: string, handle: (interaction: ButtonInteraction) => void}[]};
|
||||||
Reference in New Issue
Block a user