I want to show buttons on a message, but only allow the original requester of the message to interact with the buttons. If anybody else clicks the buttons then I want to send them a secret message telling them that their click was ignored.
I've been looking into this for a while and I keep finding people saying that it's not possible, but yet the Dank Memer bot already does exactly this! If you click a button on somebody else's message then the bot will send you a message saying "This menu is not for you." and it will say "Only you can see this message"
Currently I have this code
const collector = message.createMessageComponentCollector({ componentType: "BUTTON", time: 15000});
collector.on("collect",collected => {
if(collected.user.id !== interaction.user.id){
//collected.member.send("This command is being controlled by somebody else.");
// What can I put in here to send an ephemeral message to collected.user?? I can send them a DM using .send(), but that's not what I want.
return;
}
if(collected.customId === "confirm"){
interaction.followUp("Success");
}else{
interaction.followUp("Ignore");
}
});
Here's a picture of Dank Memer doing it... Which leads me to believe it's possible. (He said this in response to me asking for a leaderboard on one account and then trying to navigate it on a different account.)
Please tell me how this is done!
Based on this example from the discord.js guide you are able to do this by replying to the collected object as it represents an interaction:
collector.on("collect",collected => {
// Replies to the user who clicked a button that wasn't theirs
if(collected.user.id !== interaction.user.id){
collected.reply({ content: `These buttons aren't for you!`, ephemeral: true })
return;
}
if(collected.customId === "confirm"){
interaction.followUp("Success");
} else {
interaction.followUp("Ignore");
}
});
To make your reply ephemeral you have to use interaction.reply and get such code:
interaction.reply({ content: `text`, ephemeral: true })