Skip to content

Random "Unknown interaction" errors sometimes #7005

@ikheetjeff

Description

@ikheetjeff

Issue description

I have a bot with clicks on buttons every second and people executing commands. This generally goes very well, but sometimes I get an "Unknown Interaction" when I defer to it.

I've been debugging for the past three days and can't seem to understand why it's happening. My last possible explanation is an error in Discord.js or on the side of Discord.

I have attached a few screenshots describing the error
Screenshot_17
Screenshot_18

I would prefer to know if this is due to my code, or Discord.js or Discord itself.

Code sample

// Button Handler
        if(interaction.isButton()) {
            console.log(customId);
            const button = client.buttons.get(customId);
            if(!button) return;

            let {
                cooldown = -1,
                deferUpdate = false
            } = button;

            if(deferUpdate) {
                console.error('defer button');
                const testHook = interaction;
                console.error(interaction.member.user.username, interaction.member.id)
                await interaction.deferUpdate();
                console.error("doei", interaction.member.user.username, interaction.member.id)
                
            }
            
            let buttonName = (customId.startsWith('games-all-')) ? "btn-games-all" : "btn-" + customId;
            console.log(buttonName);
            if(!cooldownButtons.has(buttonName)) {
                console.log(buttonName, 'add cooldown')
                cooldownButtons.set(buttonName, new Collection());
            }

            const currentBtnTime = Date.now();
            const timestamps = await cooldownButtons.get(buttonName);
            const cooldownAmount = (cooldown) * 1000;

            if(timestamps.has(member.id)) {
                console.log(member.id, 'heeft cooldown')
                const expirationTime = timestamps.get(member.id) + cooldownAmount;

                if(currentBtnTime < expirationTime) {
                    console.log(member.id, 'heeft cooldown')
                    const time_left = (expirationTime - currentBtnTime) / 1000;

                    if(deferUpdate) {
                        return interaction.followUp({content: `**Cooldown:** You have to wait ${time_left.toFixed(1)} seconds.`, ephemeral: true});
                    }else{
                        return interaction.followUp({content: `**Cooldown:** You have to wait ${time_left.toFixed(1)} seconds.`, ephemeral: true});
                    }
                }
            }else{
                timestamps.set(member.id, currentBtnTime);
                setTimeout(() => timestamps.delete(member.id), cooldownAmount);

                try{
                    await button.execute(interaction);
                }catch(error) {
                    console.error(error);
                }
            }
        }

discord.js version

13.3.1

Node.js version

16.13.0

Operating system

Debian 10

Priority this issue should have

Medium (should be fixed soon)

Which partials do you have configured?

CHANNEL, GUILD_MEMBER, MESSAGE, REACTION

Which gateway intents are you subscribing to?

GUILDS, GUILD_MEMBERS, GUILD_INVITES, GUILD_VOICE_STATES, GUILD_MESSAGES, GUILD_MESSAGE_REACTIONS, DIRECT_MESSAGES

I have tested this issue on a development release

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions