Skip to content
This repository has been archived by the owner on Aug 30, 2022. It is now read-only.

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

Closed
IxAlpha opened this issue Apr 19, 2022 · 34 comments
Closed

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

IxAlpha opened this issue Apr 19, 2022 · 34 comments

Comments

@IxAlpha
Copy link

IxAlpha commented Apr 19, 2022

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
Copy link

Luncaaa commented Apr 19, 2022

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
Copy link
Author

IxAlpha commented Apr 20, 2022

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
Copy link

Do you have on the interactionCreate event a deferReply method?

@IxAlpha
Copy link
Author

IxAlpha commented Apr 20, 2022

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
Copy link

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
Copy link
Author

IxAlpha commented Apr 20, 2022

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
Copy link

The problem is the thing that i said to you

@PabloRNC
Copy link

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
Copy link

Try It and you Will se

@PabloRNC
Copy link

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

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

@IxAlpha
Copy link
Author

IxAlpha commented Apr 20, 2022

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

@PabloRNC
Copy link

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
Copy link

PabloRNC commented Apr 20, 2022

If you do not understand something let me know

@PabloRNC
Copy link

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

@IxAlpha
Copy link
Author

IxAlpha commented Apr 20, 2022

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
Copy link
Author

IxAlpha commented Apr 20, 2022

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

@PabloRNC
Copy link

Whats the name of your command?

@IxAlpha
Copy link
Author

IxAlpha commented Apr 20, 2022

wordle

@PabloRNC
Copy link

PabloRNC commented Apr 20, 2022

ok

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

Like that and only you try the command and luckily it will works propertly

@PabloRNC
Copy link

in cmd put how you define your command

@IxAlpha
Copy link
Author

IxAlpha commented Apr 20, 2022

okay I'll try

@IxAlpha
Copy link
Author

IxAlpha commented Apr 20, 2022

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

@IxAlpha
Copy link
Author

IxAlpha commented Apr 20, 2022

Well nope, still facing the issue...

@PabloRNC
Copy link

Show your interactionCreate

@AidanOfficial
Copy link

@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
Copy link

Show me your command and your interactionCreate

@xOnlyFadi
Copy link

@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
Copy link

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

@PabloRNC
Copy link

@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
Copy link

@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

2022-04-30.12-45-56.mp4

@PabloRNC
Copy link

PabloRNC commented May 1, 2022

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

@xOnlyFadi
Copy link

xOnlyFadi commented May 1, 2022

I tried it and I just got undefined

@Mateo-tem
Copy link
Owner

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

@IxAlpha
Copy link
Author

IxAlpha commented Jun 16, 2022

nvm djs v13.7 released already

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants