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
b1nzeeβ€’15mo 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!β€’15mo ago
hm so for ex the ID would be wipe-accept_intuserid_memid
b1nzee
b1nzeeβ€’15mo 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!β€’15mo ago
well for this instance, I'm including another ID for a member arg like >cmd @mem so im adding that as well
b1nzee
b1nzeeβ€’15mo ago
Well, then yeah, should return them as an object in the this.some()
πŸŽƒ ararou!
πŸŽƒ ararou!β€’15mo 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
b1nzeeβ€’15mo ago
WaitWhat
πŸŽƒ ararou!
πŸŽƒ ararou!β€’15mo ago
i mean it worksℒ️
b1nzee
b1nzeeβ€’15mo ago
Why are you checking if it starts with the interaction.user.id (person pressing the button)
πŸŽƒ ararou!
πŸŽƒ ararou!β€’15mo ago
kekw
No description
b1nzee
b1nzeeβ€’15mo ago
I'm just gonna take myself out of this thread, this has just brainfucked me
πŸŽƒ ararou!
πŸŽƒ ararou!β€’15mo ago
lmfaoo dw ill fix it later in 50 years
Want results from more Discord servers?
Add your server