I am making a ban command with confirmation thingy. I use buttons and MessageComponentCollector for it. However it fails and outputs the error. Here's my code:
var bu1tton = new Discord.MessageButton()
.setStyle(`SUCCESS`)
.setEmoji(`872905464797605938`)
.setLabel(`Proceed`)
.setCustomId("proceed")
var bt1 = new Discord.MessageButton()
.setStyle("DANGER")
.setEmoji(`872905464747286598`)
.setLabel(`Cancel`)
.setCustomId("back")
var row = new Discord.MessageActionRow()
.addComponents([bu1tton, bt1])
const confirmation = interaction.followUp({
embeds: [new Discord.MessageEmbed().setTitle(`Are you sure?`).setColor("RED").setDescription(`Are you sure you want to ban **${target.user.tag}** for ${reason}?\nThis action will be automatically canceled in 10 seconds if you do not select any option.`).setFooter(interaction.guild.name)],
components: [row]
})
const filter = ( inter ) => inter.user.id === interaction.user.id
const collector = confirmation.createMessageComponentCollector({ filter, time: 10000 })
collector.on('collect', async interaction => {
if(interaction.customId === "proceed") {
interaction.deferReply()
await interaction.followUp({
content: `**${interaction.user.tag}** banned **${target.user.tag}**.\nReason: *${reason}*.`
})
const reportChannel = interaction.guild.channels.cache.get(log_channel)
const messageLink = `https://discord.com/channels/${interaction.guild.id}/${interaction.channel.id}/${interaction.id}`;
let logchat = new Discord.MessageEmbed()
.setAuthor(`${interaction.user.tag} (${interaction.user.id})`, interaction.user.displayAvatarURL())
.setDescription(`**<:target:890913045126213633> Member:** ${target.user} (${target.user.id})\n**<:law:913487126576914502> Action:** Ban\n**<:decision:890913045537235005> Reason:** ${reason}\n**<:link:907511618097803284> Link:** [Click here](${messageLink})`)
.setColor('RED')
.setFooter(`ID: ${uuidv4()}`)
.setTimestamp();
const log = await reportChannel.send({
embeds: [logchat]
})
const data = log.embeds[0]
let dmembed = new Discord.MessageEmbed()
.setTitle("You have been banned from Rice Farm #11")
.setDescription(`If you find this ban abusive or wrong, please proceed to [Ban Appeal page](https://ricesupport.brizy.site/).`)
.addField("Moderator", `${interaction.user}`)
.addField("Reason", `${reason}`)
.setColor("RED")
.setFooter(`${data.footer.text}`)
.setTimestamp();
await target.send({
embeds: [dmembed]
}).catch((err) => console.log(err));
await target.ban({
reason: `Banned by ${interaction.user.tag} | Reason: ${reason}`,
days: num
}).catch((err) => console.log(err));
}
if(interaction.customId === "back") {
interaction.deferReply()
interaction.message.delete()
}
})
collector.on('end', async interaction => {
})
It sends the embed with components, but the collector obviously won't create.
Here's the full error:
[Error Handling System] Unhandled Rejection/Catch
TypeError: confirmation.createMessageComponentCollector is not a function
at Object.run (/PC/184395345943/slash/Moderation/ban.js:114:36) Promise {
<rejected> TypeError: confirmation.createMessageComponentCollector is not a function
at Object.run (/PC/184395345943/slash/Moderation/ban.js:114:36)
}
I tried changing confirmation.createMessageComponentCollector(...)
line to confirmation.message.createMessageComponentCollector(...)
, but it output almost the same error:
confirmation.message.createMessageComponentCollector() - undefined
This made me confusing. Thank you in advance! <3
CodePudding user response:
followUp
returns a Promise <(Message|APIMessage )>
, see for example this doc. So you need to await
on it:
const confirmation = await interaction.followUp({
...