DiscordJS-Example/events/members/guildMemberAdd.js

21 lines
524 B
JavaScript
Raw Normal View History

2024-03-02 22:49:13 +00:00
import { Events, GuildMember } from 'discord.js';
2024-03-02 23:46:44 +00:00
import { Role } from '../../../database.js';
2024-03-02 22:49:13 +00:00
export const name = Events.GuildMemberAdd;
/** @param {GuildMember} member */
2024-03-02 23:46:44 +00:00
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));
2024-03-02 22:49:13 +00:00
}