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 toolkit12mo 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/luna12mo ago
check with <GuildMember>.permissions.had()
Lixeiro Charmoso
Lixeiro CharmosoOP12mo ago
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/luna12mo ago
you cant do that with promisified collectors
Lixeiro Charmoso
Lixeiro CharmosoOP12mo ago
So how should i do that?
treble/luna
treble/luna12mo ago
you'd have to create a refular one and listen for the ignore event
d.js docs
d.js docs12mo ago
method Message#createMessageComponentCollector() Creates a message component interaction collector.
treble/luna
treble/luna12mo ago
and dont call it on the channel either
Lixeiro Charmoso
Lixeiro CharmosoOP12mo ago
Thank you for the fast response. It worked
Want results from more Discord servers?
Add your server