From 257191b1837c0a051c8aae3000dfac039b4d3c1b Mon Sep 17 00:00:00 2001 From: Kuilin Li Date: Sun, 12 Sep 2021 23:08:33 +0000 Subject: [PATCH] Remove Manage Messages perms requirement by only deleting own reactions --- src/bot.ts | 2 +- src/utils/loading-message.ts | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/bot.ts b/src/bot.ts index 61c0271..1b8f8dd 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -96,7 +96,7 @@ export default class { }); this.client.on('ready', async () => { - console.log(`Ready! Invite the bot with https://discordapp.com/oauth2/authorize?client_id=${this.clientId}&scope=bot&permissions=36760640`); + console.log(`Ready! Invite the bot with https://discordapp.com/oauth2/authorize?client_id=${this.clientId}&scope=bot&permissions=36752448`); }); this.client.on('error', console.error); diff --git a/src/utils/loading-message.ts b/src/utils/loading-message.ts index 115aff2..95c7a2f 100644 --- a/src/utils/loading-message.ts +++ b/src/utils/loading-message.ts @@ -64,15 +64,17 @@ export default class { this.isStopped = true; - if (str) { - if (wasAlreadyStopped) { - await this.msg.edit(str); - } else { - await Promise.all([this.msg.reactions.removeAll(), this.msg.edit(str)]); - } - } else { - await this.msg.reactions.removeAll(); - } + const editPromise = str ? this.msg.edit(str) : null; + const reactPromise = str && !wasAlreadyStopped ? (async () => { + await this.msg.fetch(); + await Promise.all(this.msg.reactions.cache.map(async react => { + if (react.me) { + await react.users.remove(this.msg.client.user!.id); + } + })); + })() : null; + + await Promise.all([editPromise, reactPromise]); return this.msg; }