discord.js-pagination icon indicating copy to clipboard operation
discord.js-pagination copied to clipboard

Missing Manage Messages Permission

Open hrrstuart opened this issue 4 years ago • 4 comments

The script should be able to handle if the bot does not have MANAGE_MESSAGES permissions. This is useful if the guild owner does not want the bot to have MANAGE_MESSAGES as opposed to requiring it just to remove reactions

hrrstuart avatar Feb 07 '21 18:02 hrrstuart

You may want to handle this on the command level, e.g. prevent the command if your bot doesn't have the required permissions for it to work. How you do this depends on whether you have your own command handler, something like commando, akairo, etc. it should not be implemented on this level.

The reason remove reaction is required, is so the user doesn't have to click the react twice after the initial react in order for it to change pages.

The collect event is fired for a new reaction, not a removed one. If the bot doesn't do it, then the user will have to un-react, then react again for a change.

psibean avatar Feb 10 '21 04:02 psibean

You may want to handle this on the command level, e.g. prevent the command if your bot doesn't have the required permissions for it to work. How you do this depends on whether you have your own command handler, something like commando, akairo, etc. it should not be implemented on this level.

The reason remove reaction is required, is so the user doesn't have to click the react twice after the initial react in order for it to change pages.

The collect event is fired for a new reaction, not a removed one. If the bot doesn't do it, then the user will have to un-react, then react again for a change.

Hey, what if we don't mind it? The menu works without the permissions. Where would we catch the unhandled error cause it's filling up my commamd prompt. Also a solution wouldn't be to just add a remove reaction listener if the bot doesn't have manage messages? It would fire the add reaction listener.

xMyThoLoGyx avatar Apr 22 '21 11:04 xMyThoLoGyx

You may want to handle this on the command level, e.g. prevent the command if your bot doesn't have the required permissions for it to work. How you do this depends on whether you have your own command handler, something like commando, akairo, etc. it should not be implemented on this level. The reason remove reaction is required, is so the user doesn't have to click the react twice after the initial react in order for it to change pages. The collect event is fired for a new reaction, not a removed one. If the bot doesn't do it, then the user will have to un-react, then react again for a change.

Hey, what if we don't mind it? The menu works without the permissions. Where would we catch the unhandled error cause it's filling up my commamd prompt. Also a solution wouldn't be to just add a remove reaction listener if the bot doesn't have manage messages? It would fire the add reaction listener.

The current state of the code does not allow you to catch the error. The current design is intended that you should be ensuring the permissions are available prior to creating the pagination embed.

Check my PR for a much more flexible and customizable version. I'm considering publishing this on npm myself to make it easier for people to use.

You can pass in an error handler which will catch and pass any errors thrown inside the collect listener onto you, to do what you want. The reaction collector is exposed to the error handler so if it's an odd case you can choose to stop the collector, or whatever.

Edit: commenting this here I've realized that perhaps the reaction remove call should be handled in it's own try / catch in my version so that the remainder of the handler still runs thereafter. But perhaps not, generally it's best to ensure your bot has the permissions it needs for something to work before allowing that thing to go through.

psibean avatar Apr 22 '21 12:04 psibean

I just removed the remove reaction command and no problemo! Thanks though!

xMyThoLoGyx avatar Apr 23 '21 01:04 xMyThoLoGyx