From cfc714611ef24410377b65af17bd9c349e7fce9d Mon Sep 17 00:00:00 2001 From: Baipyrus Date: Sun, 3 Mar 2024 00:46:44 +0100 Subject: [PATCH] implement guild member add event --- events/members/guildMemberAdd.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/events/members/guildMemberAdd.js b/events/members/guildMemberAdd.js index e176e68..8e732dd 100644 --- a/events/members/guildMemberAdd.js +++ b/events/members/guildMemberAdd.js @@ -1,7 +1,20 @@ import { Events, GuildMember } from 'discord.js'; +import { Role } from '../../../database.js'; export const name = Events.GuildMemberAdd; /** @param {GuildMember} member */ -export function execute(member) { - console.log(member); +export async function execute(member) { + // Find roles to be assigned in guild from database + const roles = await Role.findAll({ + where: { + guild: member.guild.id, + assign: true + } + }); + + // Ignore if no none found + if (roles.length === 0) return; + + // Add roles to member + member.roles.add(roles.map((role) => role.id)); }