From 13ebaa54bc66b297c365de03880ed418897b1575 Mon Sep 17 00:00:00 2001 From: Abheek Dhawan Date: Wed, 23 Mar 2022 16:00:05 -0500 Subject: [PATCH] Use a button instead of reaction for overriding answers --- src/commands/train.ts | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/commands/train.ts b/src/commands/train.ts index c95dc67..b9c5145 100644 --- a/src/commands/train.ts +++ b/src/commands/train.ts @@ -145,25 +145,31 @@ export async function execute(interaction) { .setDescription('It seems your answer was incorrect. Please react with <:override:955265585086857236> to override your answer if you think you got it right.') .setColor('#ffffff') .setTimestamp(); + const overrideButton = new MessageActionRow() + .addComponents( + new MessageButton() + .setCustomId('override') + .setEmoji('<:override:955265585086857236>') + .setStyle('SECONDARY'), + ); answerMsg.channel.send({ embeds: [overrideEmbed], + components: [overrideButton], }) .then(overrideMsg => { - overrideMsg.react('<:override:955265585086857236>'); - const filter = (reaction, user) => { + const overrideFilter = i => { return ( - ['override'].includes(reaction.emoji.name) && - user.id === answerMsg.author.id + ['override'].includes(i.customId) && + i.user.id === answerMsg.author.id ); }; overrideMsg - .awaitReactions({ - filter: filter, - max: 1, + .awaitMessageComponent({ + filter: overrideFilter, }) - .then(() => { + .then(i => { updateScore(true, score, authorId).then((msgToReply) => - answerMsg.reply(msgToReply), + i.reply(msgToReply), ); }).catch(err => log({ logger: 'train', content: `Failed to override score: ${err}`, level: 'error' })); }).catch(err => log({ logger: 'train', content: `Failed to send override message: ${err}`, level: 'error' }));