feat(command): enhance ping command with button interaction and improved response format

This commit is contained in:
2025-10-29 15:36:45 +01:00
parent 86a7429711
commit 7f9468bc99
2 changed files with 51 additions and 10 deletions

View File

@@ -1,4 +1,4 @@
import { ApplicationIntegrationType, ChatInputCommandInteraction, CommandInteraction, InteractionContextType, SlashCommandBuilder } from "discord.js";
import { ApplicationIntegrationType, ButtonInteraction, ButtonStyle, ChatInputCommandInteraction, CommandInteraction, ComponentType, ContainerBuilder, InteractionContextType, MessageFlags, SlashCommandBuilder } from "discord.js";
export default {
data: new SlashCommandBuilder()
@@ -14,6 +14,33 @@ export default {
InteractionContextType.PrivateChannel
),
async execute(interaction : ChatInputCommandInteraction) {
await interaction.reply(`🏓 Latency is ${Date.now() - interaction.createdTimestamp}ms. API Latency : ${interaction.client.ws.ping}ms`);
}
const container = new ContainerBuilder()
.addTextDisplayComponents((textDisplay) => textDisplay.setContent(`🏓 Latency is ${Date.now() - interaction.createdTimestamp}ms. API Latency : ${interaction.client.ws.ping}ms`))
.addSeparatorComponents((s) => s)
.addSectionComponents((section) =>
section
.addTextDisplayComponents((textDisplay) =>
textDisplay
.setContent('Oh, that\'s a beautiful button!')
)
.setButtonAccessory((button) =>
button
.setCustomId('testClick')
.setLabel('Click Me !')
.setStyle(ButtonStyle.Success)
)
)
// await interaction.reply();
await interaction.reply({
components: [container],
flags: MessageFlags.IsComponentsV2
})
},
buttons: [
{id: 'testClick', handle: (interaction : ButtonInteraction) => {
interaction.reply({content: 'Ho !', flags: [MessageFlags.Ephemeral]})
}}
]
}