Role buttons

This commit is contained in:
Tarrgon
2026-06-12 12:33:41 -04:00
parent 85f9eb7877
commit 38ddcde06c
5 changed files with 133 additions and 1 deletions
+32
View File
@@ -0,0 +1,32 @@
import { ButtonInteraction, Client, MessageFlags } from 'discord.js';
import { Database } from '../shared/Database';
export default {
name: 'role-button',
handler: async function (client: Client, interaction: ButtonInteraction) {
await interaction.deferReply({ flags: [MessageFlags.Ephemeral] });
const roleId = await Database.getRoleFromButton(interaction.message.id);
if (!roleId) await interaction.editReply({ content: 'Could not find role button.' });
const guild = await interaction.guild?.fetch();
const member = await guild?.members.fetch(interaction.user.id);
if (!member) return interaction.editReply({ content: 'Member not found.' });
try {
if (member.roles.cache.has(roleId!)) {
await member.roles.remove(roleId!);
interaction.editReply({ content: 'Role removed.' });
} else {
await member.roles.add(roleId!);
interaction.editReply({ content: 'Role added.' });
}
} catch (e) {
console.error(e);
interaction.editReply({ content: 'Could not add role. Is it higher than mine?' });
}
}
};