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:
JavaScript
x
6
1
client.on('interactionCreate', async interaction => {
2
const filter = m => !m.author.bot && m.author.id === interaction.user.id;
3
const collector = interaction.channel.createMessageCollector({filter, max:1, time:10000});
4
5
if (!interaction.isButton() && interaction.user.id != interaction.message.author.id) return;
6
I tried to use interaction.user.id !=
or === interaction.message.author.id
but that doesn’t work
Advertisement
Answer
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}
JavaScript
1
8
1
if(!interaction.isButton()) return;
2
if (!interaction.customId.endsWith(interaction.user.id)) {
3
return interaction.reply({
4
content: "This button is not for you",
5
ephemeral: true
6
})
7
}
8