Files
amari/src/modules/logMenteeLeave.ts
T
naomi bfaf757d3e
Node.js CI / Lint and Test (push) Successful in 45s
feat: track if mentees join or leave
2025-09-02 19:34:24 -07:00

45 lines
1.2 KiB
TypeScript

/**
* @copyright NHCarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { ids } from "../config/ids.js";
import { logger } from "../utils/logger.js";
import type { Amari } from "../interfaces/amari.js";
import type { GuildMember, PartialGuildMember } from "discord.js";
/**
* Run when a guild member leaves. If the member had the mentorship role,
* notify Naomi.
* @param amari - Amari's instance.
* @param member - The member payload from Discord.
*/
export const logMenteeLeave = async(
amari: Amari,
member: GuildMember | PartialGuildMember,
): Promise<void> => {
if (!member.roles.cache.has(ids.roles.mentorship)) {
return;
}
const channel = amari.discord.channels.cache.get(ids.channels.menteeChat)
?? await amari.discord.channels.fetch(ids.channels.menteeChat);
if (channel?.isSendable() !== true) {
await logger.log(
"warn",
"Mentee Chat channel does not exist or is not sendable.",
);
return;
}
await channel.send({
content: `Hey <@${ids.users.naomi}>~!
<@${member.id}> (${member.user.displayName} - ${member.id}) has left the server.
It seems they were part of the mentorship programme, so you may need to offboard them.`,
});
};