add iUseSHSF listener to manage role assignment based on user messages
All checks were successful
CI / build (push) Successful in 10s

This commit is contained in:
Space-Banane
2026-02-22 17:23:13 +01:00
parent 77279c778d
commit 1e4a83c0a5

View File

@@ -0,0 +1,80 @@
import { Client, Events, Message } from "discord.js";
import { ROLES } from "../../config";
export default async function iUseSHSFListener(client: Client): Promise<void> {
client.on(Events.MessageCreate, async (message: Message) => {
// Ignore messages from bots or non-guild messages
if (message.author.bot || !message.guild) return;
const content = message.content.toLowerCase();
// Grant role if user says "i use shsf"
if (content.includes("i use shsf")) {
const member = await message.guild.members
.fetch(message.author.id)
.catch(() => null);
if (!member) return;
// Check if the member already has the role
if (member.roles.cache.has(ROLES.I_USE_SHSF)) return;
await member.roles.add(ROLES.I_USE_SHSF);
await message.reply({
embeds: [
{
title: "Role Granted!",
description:
"You have been given the **I Use SHSF** role.",
color: 0x00ff00,
},
],
});
return;
}
// Remove role if user says they dont use it
if (
content.includes("i don't use shsf") ||
content.includes("i dont use shsf") ||
content.includes("i do not use shsf")
) {
const member = await message.guild.members
.fetch(message.author.id)
.catch(() => null);
if (!member) return;
// Only remove if the member has the role
if (!member.roles.cache.has(ROLES.I_USE_SHSF)) return;
try {
await member.roles.remove(ROLES.I_USE_SHSF);
await message.reply({
embeds: [
{
title: "Role Removed",
description:
"The **I Use SHSF** role has been removed from you.",
color: 0xff0000,
},
],
});
} catch (error) {
console.error(
"Failed to remove I_USE_SHSF role from member:",
message.author.id,
error,
);
await message.reply({
embeds: [
{
title: "Error Removing Role",
description:
"I couldn't remove the **I Use SHSF** role. This may be due to missing permissions or a temporary issue. Please try again later or contact a server admin.",
color: 0xff0000,
},
],
});
}
}
});
}