turtlepaws-workshop / Tutorial-djs-bot

0 stars 2 forks source link

Error "INTERACTION_ALREADY_REPLIED" #1

Closed RaksoFox closed 2 years ago

RaksoFox commented 2 years ago

After trying to send the modal, the bot displays the following error: image

Turtlepaw commented 2 years ago

Can you show your code?

Turtlepaw commented 2 years ago

And does this solve your problem?

RaksoFox commented 2 years ago

Can you show your code?


import {SlashCommandBuilder}                  from '@discordjs/builders'
import {Modal, showModal, TextInputComponent} from 'discord-modals';
import {MessageButton}                        from 'discord.js';

const {v4} = require("uuid");

module.exports = { data: new SlashCommandBuilder() .setName('modal') .setDescription('Amazing Modal!'), async execute(interaction: any, client: any) { const customIds = { MODAL: DISCORD_MODAL + v4(), BUTTON: EXECUTE_MODAL }

    const SentMessage = await interaction.reply({
        content: `Click the button below for a modal.`,
        components: [
            {
                type: 1,
                components: [
                    new MessageButton()
                        .setCustomId(customIds.BUTTON)
                        .setLabel(`Show Modal`)
                        .setStyle("PRIMARY")
                ]
            }
        ],
        fetchReply: true
    });

    await SentMessage.awaitMessageComponent({
        filter: (i: any) => i.user.id == interaction.user.id,
        componentType: "BUTTON"
    }).then(async (btn: any) => {
        const modal = new Modal()
            .setCustomId(customIds.MODAL)
            .setTitle(`Title`)
            .setComponents(
                new TextInputComponent()
                    .setCustomId(`TEXT`)
                    .setLabel(`Why you won't work qwq`)
                    .setRequired(true)
                    .setStyle("SHORT")
                    .setPlaceholder(`Enter some letters..`),
            );

        await showModal(modal, {
            client,
            interaction: btn
        });

        client.on("modalSubmit", async (m: any) => {
            const text = m.getTextInputValue("TEXT");

            await m.reply({
                content: `You applied for mod!\n\nReason: \`${text}\``
            });
        });
    });
},

};

Turtlepaw commented 2 years ago

You should probably post this in Discord Modals repository.

But have you initiated Discord Modals?

RaksoFox commented 2 years ago

Okay. For now i switch to Discord JS v14 where models are supported and its works fine. And Yes, I have modals initialed.