Meaning: there is some content and a button in the response to the slash command. The task of the button is to delete the message. What we managed to do was to force the button to delete the message, but the problem is that not only the message in which the button is deleted, but also other messages.
const {
MessageEmbed,
MessageActionRow,
MessageButton
} = require('discord.js')
const {
SlashCommandBuilder
} = require('@discordjs/builders')
const Color = 'RANDOM'
module.exports = {
name: 'Name',
data: new SlashCommandBuilder()
.setName('Name')
.setDescription('Description')
.addStringOption(option => option.setName('choice')
.setDescription('Description')
.setRequired(true)
.addChoice('choice1', 'choice1')
.addChoice('choice2', 'choice2')
.addChoice('choice3', 'choice3')
async run(interaction) {
const Embed = new MessageEmbed()
.setColor(Color)
.setTimestamp()
.setImage(url)
const Btns = new MessageActionRow()
.addComponents(new MessageButton()
.setCustomId('DeleteMsg')
.setStyle('DANGER')
.setLabel('Удалить сообщение (Только автор или администратор)'))
interaction.reply({
embeds: [Embed],
components: [Btns]
})
try {
const collector = interaction.channel.createMessageComponentCollector({
time: 60000
})
collector.on('collect', async i => {
interaction.deleteReply()
})
} catch (error) {
console.log(error)
}
}
}
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Ok first of all, you should always add a filter to your component collector.
(How many items to collect, check if correct users used your component, …)
You should also have a real custom ID (like an UUID or something like that) because if there’s multiple calls of your command in the same channel then, your custom ID wouldn’t be custom anymore and could be collected by every collector running in the channel.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0