LeaPhant/skyflower

Respond to button interactions from the wrong user

Closed this issue · 2 comments

When users click a button that they're not supposed to be touching, the bot discards the interaction, and discord displays that the interaction fails after a moment of processing. (Shown below)

image

Here is the code that causes this in the /lb command (though this issue exists everywhere where button interactions from other users are ignored)

const filter = i => i.user.id === interaction.user.id;

It's generally good practice to ensure that all interactions received by bots should be responded to, a simple fix to this would be having a generic response that can be expanded if you wish as you see fit.

Here's a potential fix as just a change to the filter function:

const filter = i => {
    if (i.user.id === interaction.user.id) return true;
    
    i.reply({ 
        content: "This button isn't meant for you! Please run the command yourself.",
        ephemeral: true
    });
    
    return false;
}

Honestly, I don't remember if a system like this would work as part of the filter function without testing it myself, but I'm sure it's clear how to go from here and prevent the interaction failed message.

This is intentional design cause I don't like the solution of taking up space in chat. Still waiting for a more elegant way to handle unauthorized button presses (or a way to show buttons as disabled to unauthorized users).

That solution doesn't take space in chat, it sends an ephemeral message that is only visible to the recipient and can easily be dismissed. Your current method of leaving it as shows up as an error in the eyes of the user which confuses people and is bad UX.

I agree that there should be a more elegant way, but this is the current method we have and it's easily dismissed.

Ex:
image