Skip to content

Commit

Permalink
Add special role if reacted with special emote
Browse files Browse the repository at this point in the history
  • Loading branch information
89Q12 committed Feb 4, 2024
1 parent b47534b commit 83c49cf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions backend/src/bot/guards/reaction-emote.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { CanActivate, ExecutionContext, mixin } from '@nestjs/common';

import { MessageReaction } from 'discord.js';

export const ReactionEmoteGuard = (emote: string) => {
export const ReactionEmoteGuard = (emotes: string[]) => {
class ReactionEmote implements CanActivate {
canActivate(context: ExecutionContext): boolean {
const reaction = context.getArgByIndex(0);
if (
reaction instanceof MessageReaction &&
(reaction as MessageReaction).emoji.name === emote
emotes.includes((reaction as MessageReaction).emoji.name)
) {
return true;
}
Expand Down
6 changes: 4 additions & 2 deletions backend/src/guild/events/guild-members/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
Client,
GuildMember,
MessageReaction,
User,
GuildTextBasedChannel,
Message,
} from 'discord.js';
Expand Down Expand Up @@ -59,7 +58,8 @@ export class GuildMemberEvents {
@On('messageReactionAdd')
@UseGuards(
ReactionChannelIdGuard('1121822614374060175'),
ReactionEmoteGuard('✅'),

ReactionEmoteGuard(['✅', '☑️']),
ReactedMemberIsModOrHigherGuard,
)
async unlockUser(reaction: MessageReaction) {
Expand Down Expand Up @@ -92,6 +92,8 @@ export class GuildMemberEvents {
reaction.message.guildId,
);
await member.roles.add(verifiedRoleId);
if (reaction.emoji.name === '☑️')
await member.roles.add('1014066383912439809');
// Wait 500ms to make sure the role is added before removing the unverified role
//https://github.com/discordjs/discord.js/issues/4930#issuecomment-1042351896
await new Promise((resolve) => setTimeout(resolve, 500));
Expand Down

0 comments on commit 83c49cf

Please sign in to comment.