Receiving specific buttons

if (interaction.type === ComponentType.Button){
console.log('Captcha')
console.log(interaction.customId === 'captchaIns')
if (interaction.customId === 'captchaIns'){
console.log('Captcha')
}
}
if (interaction.type === ComponentType.Button){
console.log('Captcha')
console.log(interaction.customId === 'captchaIns')
if (interaction.customId === 'captchaIns'){
console.log('Captcha')
}
}
Here is my button builder
const instructionsButton = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId('captchaIns')
.setLabel('I have read the Instuctions')
.setEmoji(':unlock_1:')
.setStyle(ButtonStyle.Secondary)
)
const instructionsButton = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId('captchaIns')
.setLabel('I have read the Instuctions')
.setEmoji(':unlock_1:')
.setStyle(ButtonStyle.Secondary)
)
Console Output
Captcha
false
Captcha
false
How do wait and get the customId of the button
10 Replies
d.js docs
d.js docs2y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
PAdventures
PAdventures2y ago
discord.js@14.0.1
Node: v16.14.0
discord.js@14.0.1
Node: v16.14.0
조아오
조아오2y ago
You can: Create a collector or listen to the interactionCreate event and add the proper filter to execute the function you want
d.js docs
d.js docs2y ago
guide Interactions: Component collectors read more
조아오
조아오2y ago
It has an hyperlink to the collectors guide
PAdventures
PAdventures2y ago
where do i put the collector, in the interactionCreate or the file where the button is? If i add this
const collector = message.createMessageComponentCollector({ componentType: ComponentType.Button});

collector.on('collect', i => {
if (i.customId === 'captchaIns'){
console.log('ABC')
}
});
const collector = message.createMessageComponentCollector({ componentType: ComponentType.Button});

collector.on('collect', i => {
if (i.customId === 'captchaIns'){
console.log('ABC')
}
});
into my interactionCreate file, it will log ABC?
조아오
조아오2y ago
The file where you reply to the interaction
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
PAdventures
PAdventures2y ago
already specified -> false
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View