I'm trying to make a bot that lets users create embeds using a series of commands and its going well. But I encountered a problem, the bot uses buttons but to confirm something like "Are you sure this is your title?" any user can click the button; which is a problem. I only want the user who used the command to be able to use the buttons.
Here is what I tried at the start:
client.on('interactionCreate', async interaction => {
const filter = m => !m.author.bot && m.author.id === interaction.user.id;
const collector = interaction.channel.createMessageCollector({filter, max:1, time:10000});
if (!interaction.isButton() && interaction.user.id != interaction.message.author.id) return;
I tried to use interaction.user.id != or === interaction.message.author.id but that doesn't work
The best way to make a button only for a single user is to put the user ID in the custom ID
For example, set the ID to title-${interaction.user.id}
if(!interaction.isButton()) return;
if (!interaction.customId.endsWith(interaction.user.id)) {
return interaction.reply({
content: "This button is not for you",
ephemeral: true
})
}
client.on("interactionCreate", async (interaction) => {
//filter the user so it only works for the user who sent the command
if (interaction.user.id !== message.author.id) {
const embed = new MessageEmbed()
.setDescription("You Cannot Interact With This Message!")
.setColor("RED");
return interaction.reply({ embeds: [embed], ephemeral: true });
} else {
//Code Here
}
});
idk if you still need it but
hope it works, it works for me