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

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)
12 Replies
b1nzee
b1nzee16mo ago
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();
return interaction.customId.startsWith("test_button_") ? this.some(interaction.customId.split("_")[2]) : this.none();
That would be your parse function in the interaction handler
ararou!
ararou!OP16mo ago
hm so for ex the ID would be wipe-accept_intuserid_memid
b1nzee
b1nzee16mo ago
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
ararou!
ararou!OP16mo ago
well for this instance, I'm including another ID for a member arg like >cmd @mem so im adding that as well
b1nzee
b1nzee16mo ago
Well, then yeah, should return them as an object in the this.some()
ararou!
ararou!OP16mo ago
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`);
}
}
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
b1nzee
b1nzee16mo ago
WaitWhat
ararou!
ararou!OP16mo ago
i mean it works™️
b1nzee
b1nzee16mo ago
Why are you checking if it starts with the interaction.user.id (person pressing the button)
ararou!
ararou!OP16mo ago
kekw
No description
b1nzee
b1nzee16mo ago
I'm just gonna take myself out of this thread, this has just brainfucked me
ararou!
ararou!OP16mo ago
lmfaoo dw ill fix it later in 50 years
Want results from more Discord servers?
Add your server