Adding a slash command to do the same thing a button already does

I am working on a ticket system. I have a button called "Close ticket" on a message and it is sent when a new ticket is made. When you click this button it comes up with a message asking if you are sure you want to close the ticket and that message has a "Cancel" button which deletes the message and a "Yes" button that deletes the channel. I have registered a command called /close and I want it to bring up the same message asking if you are sure you want to close the ticket. Can I do this? The code for the "closeTicket" button: } else if(interaction.customId == "closeTicket") { const confirmcloseEmbed = new EmbedBuilder() .setColor(0x2b2d31) .setAuthor({ name: 'Are you sure you want to end this conversation?', iconURL: 'Logo-02.png' }); const row = new ActionRowBuilder() .addComponents( new ButtonBuilder() .setLabel("Yes") .setCustomId("yesCloseTicket") .setStyle(ButtonStyle.Secondary), new ButtonBuilder() .setLabel("Cancel") .setCustomId("cancelCloseTicket") .setStyle(ButtonStyle.Secondary) ); interaction.reply({ ephemeral: false, components: [ row ], embeds: [ confirmcloseEmbed ] }); } else if(interaction.customId == "yesCloseTicket") { interaction.channel.delete(); } else if(interaction.customId == "cancelCloseTicket") { interaction.message.delete();
6 Replies
d.js toolkit
d.js toolkit11mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
unchill
unchill11mo ago
v18.17.0 discord.js@14.11.0
treble/luna
treble/luna11mo ago
yes, just typeguard with isChatInputCommand and use .commandName instead of customId
unchill
unchill11mo ago
How do I type guard?
treble/luna
treble/luna11mo ago
<Interaction>.isChatInputCommand()
unchill
unchill11mo ago
Okay thanks!