How to create a button with permission

Very similar to the behavior of this button "Mark post as solved" i want to create one the does basically the same. 1. If the person has permission to click it, executes the function 2. Else show a ephemeral error message to the user like "Only the original poster or support staff can mark a post as resolved!" I have this code with works to execute when the user has permission. When he does not have permission i receive the error "Interaction failed"
let botMsg = await channel.send({ embeds: [embed], components: [buttons] })

const filterComponent = (i) => Utils.isStaff(i.member);
let result = await channel.awaitMessageComponent({ filter: filterComponent, time: 300000, max: 1 });
let botMsg = await channel.send({ embeds: [embed], components: [buttons] })

const filterComponent = (i) => Utils.isStaff(i.member);
let result = await channel.awaitMessageComponent({ filter: filterComponent, time: 300000, max: 1 });
No description
9 Replies
d.js toolkit
d.js toolkit6mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
treble/luna
treble/luna6mo ago
check with <GuildMember>.permissions.had()
Lixeiro Charmoso
Hello, that is not the problem i successfully checked the user permission. The issue is when he does not have permission, the code does not defer any update to the button leading me to the "Interaction failed" error
treble/luna
treble/luna6mo ago
you cant do that with promisified collectors
Lixeiro Charmoso
So how should i do that?
treble/luna
treble/luna6mo ago
you'd have to create a refular one and listen for the ignore event
d.js docs
d.js docs6mo ago
method Message#createMessageComponentCollector() Creates a message component interaction collector.
treble/luna
treble/luna6mo ago
and dont call it on the channel either
Lixeiro Charmoso
Thank you for the fast response. It worked