Unable to show modal from button interaction. (discord V14.8.0)
Hello, I've been struggling to get the modal from my button to work. I have done everything right as far as I can tell and have no errors from my code.
const { CaptchaGenerator } = require('captcha-canvas');
const { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder, AttachmentBuilder, ModalBuilder, TextInputBuilder} = require('discord.js');
const array = [];
module.exports = {
name: 'verify',
description: 'Verify that you are not a bot',
devOnly: true,
testOnly: true,
callback: async (client, interaction) =>{
const captcha = new CaptchaGenerator()
.setDimension(150, 600)
.setCaptcha({size: 60, characters: 10})
.setDecoy({ opacity: 1, size: 40 })
.setTrace()
const buffer = captcha.generateSync();
const verifyAttachment = new AttachmentBuilder(buffer, { name: 'captcha.png'});
const embed = new EmbedBuilder()
.setTitle('Keyed Chaos Captcha')
.setDescription('Please complete the captcha!')
.setImage('attachment://captcha.png')
console.log(`Example captcha text:${captcha.text}\n`);
const target = interaction.user.id;
let checkmk = new ButtonBuilder()
.setCustomId('answer')
.setLabel('Answer Captcha')
.setStyle(ButtonStyle.Success);
const row = new ActionRowBuilder()
.addComponents(checkmk);
response = await interaction.reply({
embeds:[embed],
files: [verifyAttachment],
components: [row],
ephemeral: true});
client.on(Event.InteractionCreate, async(interaction) =>
{
if (interaction.isButton()){
if(interaction.customId === 'answer'){
const modal = new ModalBuilder()
.setCustomId('verification-modal')
.setTitle('Keyed Chaos Verification')
.addComponents([
new ActionRowBuilder().addComponents(
new TextInputBuilder()
.setCustomId('CaptchaCode')
.setLabel('Please answer the captcha')
.setStyle(TextInputStyle.Short)
.setMaxLength(10)
.setRequired(true),
),
]);
await interaction.showModal(modal);
}
}
if (interaction.type === InteractionType.ModalSubmit){
if(interaction.customId === 'verification-modal'){
const response = interaction.fields.getTextInputValue('CaptchaCode');
interaction.reply('Thank you for submitting your answer.');
}
}
});
},
};const { CaptchaGenerator } = require('captcha-canvas');
const { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder, AttachmentBuilder, ModalBuilder, TextInputBuilder} = require('discord.js');
const array = [];
module.exports = {
name: 'verify',
description: 'Verify that you are not a bot',
devOnly: true,
testOnly: true,
callback: async (client, interaction) =>{
const captcha = new CaptchaGenerator()
.setDimension(150, 600)
.setCaptcha({size: 60, characters: 10})
.setDecoy({ opacity: 1, size: 40 })
.setTrace()
const buffer = captcha.generateSync();
const verifyAttachment = new AttachmentBuilder(buffer, { name: 'captcha.png'});
const embed = new EmbedBuilder()
.setTitle('Keyed Chaos Captcha')
.setDescription('Please complete the captcha!')
.setImage('attachment://captcha.png')
console.log(`Example captcha text:${captcha.text}\n`);
const target = interaction.user.id;
let checkmk = new ButtonBuilder()
.setCustomId('answer')
.setLabel('Answer Captcha')
.setStyle(ButtonStyle.Success);
const row = new ActionRowBuilder()
.addComponents(checkmk);
response = await interaction.reply({
embeds:[embed],
files: [verifyAttachment],
components: [row],
ephemeral: true});
client.on(Event.InteractionCreate, async(interaction) =>
{
if (interaction.isButton()){
if(interaction.customId === 'answer'){
const modal = new ModalBuilder()
.setCustomId('verification-modal')
.setTitle('Keyed Chaos Verification')
.addComponents([
new ActionRowBuilder().addComponents(
new TextInputBuilder()
.setCustomId('CaptchaCode')
.setLabel('Please answer the captcha')
.setStyle(TextInputStyle.Short)
.setMaxLength(10)
.setRequired(true),
),
]);
await interaction.showModal(modal);
}
}
if (interaction.type === InteractionType.ModalSubmit){
if(interaction.customId === 'verification-modal'){
const response = interaction.fields.getTextInputValue('CaptchaCode');
interaction.reply('Thank you for submitting your answer.');
}
}
});
},
};