#How do I check if the user ID is actually equals to the user ID in interaction-handlers

1 messages · Page 1 of 1 (latest)

scenic pulsar
#

Is there a way to check if the user ID that clicked the button is equals to the user that ran the command? For example: if (interaction.user.id !== <command_user>.user.id)

little rampartBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

sudden flower
#

You can pass the user ID through the customId and get it that way

#
return interaction.customId.startsWith("test_button_") ? this.some(interaction.customId.split("_")[2]) : this.none();
#

That would be your parse function in the interaction handler

scenic pulsar
#

hm

#

so for ex the ID would be wipe-accept_intuserid_memid

sudden flower
#

You only need 1 users ID

interaction.user.id is the person who pressed the button or whatever

The ID from your customId is the person who originally executed the command

scenic pulsar
#

well for this instance, I'm including another ID for a member arg

#

like >cmd @mem

#

so

#

im adding that as well

sudden flower
#

Well, then yeah, should return them as an object in the this.some()

scenic pulsar
#

well so far seems like mine is working

#
import { InteractionHandlerTypes } from '@sapphire/framework';
import { InteractionHandler } from '@sapphire/framework';
import type { ButtonInteraction } from 'discord.js';

export class WipeCommandAcceptButton extends InteractionHandler {
  public constructor(context: InteractionHandler.Context) {
    super(context, {
      name: 'WipeCommandAcceptButton',
      interactionHandlerType: InteractionHandlerTypes.Button,
    });
  }

  public override parse(interaction: ButtonInteraction) {
    return !interaction.customId.startsWith(
      `${interaction.user.id}-wipe-accept`,
    )
      ? this.none()
      : this.some();
  }

  public run(interaction: ButtonInteraction) {
    return interaction.reply(`ok ${interaction.user} ran this button`);
  }
}
#

ya i think thisll be it

sudden flower
scenic pulsar
#

i mean

#

it works™️

sudden flower
scenic pulsar
sudden flower
#

I'm just gonna take myself out of this thread, this has just brainfucked me

scenic pulsar
#

lmfaoo

#

dw ill fix it later

#

in 50 years