Law
Law
Explore posts from servers
DIAdiscord.js - Imagine an app
Created by Law on 10/21/2023 in #djs-questions
Discord v14.8.0 Modal Submit not working.
Node version:
v18.12.1
v18.12.1
Current dependencies are as follows:
"dependencies": {
"captcha-canvas": "^3.2.1",
"discord.js": "^14.8.0",
"dotenv": "^16.0.3"
}
"dependencies": {
"captcha-canvas": "^3.2.1",
"discord.js": "^14.8.0",
"dotenv": "^16.0.3"
}
Slash command that creates an embed with a button to display a modal. The modal submit has the bot not responding at all.
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});

const filter = (interaction) => interaction.customId === 'answer';
response.awaitMessageComponent({filter, time: 15_000})
.then(interaction => {
console.log(`${interaction.customId} was clicked!`)
const modal = new ModalBuilder()
.setCustomId('verification')
.setTitle('Keyed Chaos Verification')
.addComponents([
new ActionRowBuilder().addComponents(
new TextInputBuilder()
.setCustomId('verification-answer')
.setLabel('Answer')
.setStyle(2)
.setMaxLength(10)
.setRequired(true),
),
]);
interaction.showModal(modal);

client.on(Event.InteractionCreate, async interaction =>{
if(!interaction.isModalSubmit()) return;

if(interaction.customId === 'verification'){
const modalAnswer = interaction.fields.getTextInputValue('verification-answer');
await interaction.ModalSubmitInteraction(console.log(`Answer: ${modalAnswer}\n`))
}


})
.catch(console.error);

},
}
}
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});

const filter = (interaction) => interaction.customId === 'answer';
response.awaitMessageComponent({filter, time: 15_000})
.then(interaction => {
console.log(`${interaction.customId} was clicked!`)
const modal = new ModalBuilder()
.setCustomId('verification')
.setTitle('Keyed Chaos Verification')
.addComponents([
new ActionRowBuilder().addComponents(
new TextInputBuilder()
.setCustomId('verification-answer')
.setLabel('Answer')
.setStyle(2)
.setMaxLength(10)
.setRequired(true),
),
]);
interaction.showModal(modal);

client.on(Event.InteractionCreate, async interaction =>{
if(!interaction.isModalSubmit()) return;

if(interaction.customId === 'verification'){
const modalAnswer = interaction.fields.getTextInputValue('verification-answer');
await interaction.ModalSubmitInteraction(console.log(`Answer: ${modalAnswer}\n`))
}


})
.catch(console.error);

},
}
}
17 replies
DIAdiscord.js - Imagine an app
Created by Law on 10/15/2023 in #djs-questions
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.');
}
}
});

},

};
16 replies