Mateo-tem / discord-modals

discord-modals is a package that allows your bot of discord.js v13 to create the new Discord Modals and interact with them.
https://www.npmjs.com/package/discord-modals
MIT License
93 stars 27 forks source link

[Collector Interaction] Interaction has already been acknowledged. #73

Closed IxAlpha closed 2 years ago

IxAlpha commented 2 years ago

So I've tried to use the collector interaction like:

const msg = await interaction.followUp({ components: [row5], content: `Weird button just showed up!`, ephemeral: false })
const collector = msg.createMessageComponentCollector({ time: 90000 })

collector.on('collect', async (i) => {
    if(i.customId === 'trywordbtn') {
        showModal(modal, {
            client: client,
            interaction: i
        }) 
     }
})

The first time the command works fine, but the second time I use the command I get Discord API error with "interaction has been already acknowledged. Here's the modalSubmit event:

 client.on('modalSubmit', async (modal) => {
            if(modal.customId === 'wordleinput') {
                await modal.deferReply({ ephemeral: true }) // Error from here belongs...
                const firstResponse = modal.getTextInputValue('wordinput')

                if(firstResponse === randomWordg) {
                    await modal.followUp({ content: `Congrats 🥳 You guessed the word right, and it was \`${randomWordg}\``, ephemeral: true })

                    await interaction.editReply({ content: `Good job! \`⍟Soon\` tokens has been added to your wallet.`, components: [deadraw] })

                } else if(trys === 4) {
                    await modal.followUp({ content: `You've 4 attempts to guess the word.`, ephemeral: true })

                    await interaction.editReply({ content: `Hmm... You should think more about it!`, components: [row5] })
                    trys = trys - 1

                } else if(trys === 3) {
                    await modal.followUp({ content: `\`3 of 4\` Attempts left.`, ephemeral: true })

                    await interaction.editReply({ content: `2 more attempts left, it's really easy!`, components: [row5] })

                } else if(trys === 2) {
                    await modal.followUp({ content: `\`2 of 4\` Attempts left.`, ephemeral: true })

                    await interaction.editReply({ content: `Really it's that much hard?!`, components: [row5] })
                } else if(trys === 1) {
                    await modal.followUp({ content: `\`1 of 4\` Attempts left.`, ephemeral: true })

                    await interaction.editReply({ content: `Common, think think!`, components: [row5] })
                } 

                if(trys === 0) {
                    await modal.followUp({ content: `Game end! You lost...`, ephemeral: true })

                    await interaction.editReply({ content: `You've ran out of attempts.. the word was \`${randomWordg}\``, components: [deadraw] })
                }
            }  
});

I am suffering this issue ages ago, idk what to do to solve it.. any solution??

Luncaaa commented 2 years ago

Do you have the client.on('modalSubmit) method in the same file as the command? If so, what worked for me was moving that method to another file like main.js or with an event handler.

IxAlpha commented 2 years ago

Do you have the client.on('modalSubmit) method in the same file as the command? If so, what worked for me was moving that method to another file like main.js or with an event handler.

Well, I've tried to do that so I wanted to use the interaction from the command, so I've tried to use parameters, but the same issue still appears, here's example, in the component collector:

const modalHandler = require('../../events/modalSubmit')

collector.on('collect', async (i) => {
    if(i.customId === 'button') {
        showModal({
             client: client,
             interaction: i
         })
        modalHandler(interaction, collector)
    }
})

And the event file

const modalHandler = async (interaction, collector) => {
    client.on('modalSubmit', async (modal) => {
          // Th same event code goes here
    }
}

module.exports = modalHandler
PabloRNC commented 2 years ago

Do you have on the interactionCreate event a deferReply method?

IxAlpha commented 2 years ago

Do you have on the interactionCreate event a deferReply method?

Well, I use command handler, I've used the interaction.deferReply() first and then I've used followUp to reply with the rows..

Like:

// On the top of the code
await interaction.deferReply()

// Some rows defining goes here...

// And now followUp with the components
const msg = await interaction.followUp({ ... })
PabloRNC commented 2 years ago

Delete the deferReply method and if u have followUp or editReply methods on your commands change It by reply or limit this deferReply method to all your command except this one

IxAlpha commented 2 years ago

But it's not caused from the command interaction.. I've marked from where does the error belongs to, when I use modal.deferReply() for the second time, it errors

PabloRNC commented 2 years ago

The problem is the thing that i said to you

PabloRNC commented 2 years ago

Because the collector collect those interactions and you on your interactionCreate you deferReply that interaction and the error is because you cannot deferReply this interaction and use on the show Modal method

PabloRNC commented 2 years ago

Try It and you Will se

PabloRNC commented 2 years ago

You can do this instead of replace the followUp and editReply methods


if(!<cmd> === "your_modal_command"){
interaction.deferReply()
}
IxAlpha commented 2 years ago

Alrighty, should I disable the interaction.deferReply() from the command? And use interaction.reply() instead?

PabloRNC commented 2 years ago

This code says that if the Slash is not the modal Slash deferReply that interaction if not it doesn't deferReply that interaction and in this case the whole modal command

PabloRNC commented 2 years ago

If you do not understand something let me know

PabloRNC commented 2 years ago

I think is better on github so all the users that have this problem can solve it

IxAlpha commented 2 years ago

Yeah true, anyways, I've tried to not to use Interaction#deferReply and use Interaction#reply like:

const msg = await interaction.reply({ components: [row5], content: `Weird buttons just showed up!`, ephemeral: false, fetchReply: true })
const collector = msg.createMessageComponentCollector({ time: 120000 })

But like uh, am bored like literally I don't know what to do, would be my pleasure if you explain me it step by step...

IxAlpha commented 2 years ago

ps: I use Interaction#deferReply in all of my commands not in the event itself

PabloRNC commented 2 years ago

Whats the name of your command?

IxAlpha commented 2 years ago

wordle

PabloRNC commented 2 years ago

ok



if(!<cmd> === "wordle"){
 await interaction.deferReply()
}

Like that and only you try the command and luckily it will works propertly
PabloRNC commented 2 years ago

in cmd put how you define your command

IxAlpha commented 2 years ago

okay I'll try

IxAlpha commented 2 years ago

So it has differences if I deferReply in the event or in the command file?

IxAlpha commented 2 years ago

Well nope, still facing the issue...

PabloRNC commented 2 years ago

Show your interactionCreate

AidanOfficial commented 2 years ago

@PabloRNC I'm having this same error, with nothing but the modalSubmit event giving a deferReply

you can contact me at 10KAIDAN#0001 on discord

PabloRNC commented 2 years ago

Show me your command and your interactionCreate

xOnlyFadi commented 2 years ago

@PabloRNC is it possible to edit the current message without following it up because the bot im making is using it like a ban reason and then edit the message saying banned successfully?

PabloRNC commented 2 years ago

Mmm i do not know what do you mean if can provide some screenshots

PabloRNC commented 2 years ago

@PabloRNC is it possible to edit the current message without following it up because the bot im making is using it like a ban reason and then edit the message saying banned successfully?

You can like modal.reply with fetchReply in true and then edit It like a interaction.reply method

xOnlyFadi commented 2 years ago

@PabloRNC is it possible to edit the current message without following it up because the bot im making is using it like a ban reason and then edit the message saying banned successfully?

You can like modal.reply with fetchReply in true and then edit It like a interaction.reply method

i already changed to discord.js v14 and it had the necessary things with the function awaitModalSubmit made it that i can edit current message without making it reply again

https://user-images.githubusercontent.com/63213308/166118685-80769e88-066d-41c9-9e70-9496f1682c16.mp4

PabloRNC commented 2 years ago

You can edit It with modal.interaction.message.edit on the discord -modals npm i think

xOnlyFadi commented 2 years ago

I tried it and I just got undefined

Mateo-tem commented 2 years ago

On discord-modals is modal.update(...).

IxAlpha commented 2 years ago

nvm djs v13.7 released already