Add role selection system with select menus
All checks were successful
Auto Build and Push Docker Image / build (push) Successful in 7s
All checks were successful
Auto Build and Push Docker Image / build (push) Successful in 7s
This commit is contained in:
@@ -1,8 +1,86 @@
|
||||
import { Events, MessageFlags } from 'discord.js';
|
||||
import { Events, MessageFlags, ComponentType } from 'discord.js';
|
||||
|
||||
export default {
|
||||
name: Events.InteractionCreate,
|
||||
async execute(interaction: any, client: any) {
|
||||
if (interaction.isStringSelectMenu()) {
|
||||
const customId = interaction.customId;
|
||||
|
||||
if (customId.startsWith('role_select_')) {
|
||||
const categoryName = customId.replace('role_select_', '');
|
||||
const selectedRoleId = interaction.values[0];
|
||||
const member = interaction.member;
|
||||
const guild = interaction.guild;
|
||||
|
||||
const category: any = client.DB.get(
|
||||
'SELECT * FROM role_categories WHERE guild_id = ? AND category_name = ?',
|
||||
guild.id,
|
||||
categoryName
|
||||
);
|
||||
|
||||
if (!category) {
|
||||
await interaction.reply({ content: 'Kategorie nicht gefunden.', flags: [MessageFlags.Ephemeral] });
|
||||
return;
|
||||
}
|
||||
|
||||
const option: any = client.DB.get(
|
||||
'SELECT * FROM role_options WHERE category_id = ? AND role_id = ?',
|
||||
category.id,
|
||||
selectedRoleId
|
||||
);
|
||||
|
||||
if (!option) {
|
||||
await interaction.reply({ content: 'Rolle nicht gefunden.', flags: [MessageFlags.Ephemeral] });
|
||||
return;
|
||||
}
|
||||
|
||||
const discordRole = guild.roles.cache.get(selectedRoleId);
|
||||
if (!discordRole) {
|
||||
await interaction.reply({ content: 'Diese Rolle existiert nicht mehr.', flags: [MessageFlags.Ephemeral] });
|
||||
return;
|
||||
}
|
||||
|
||||
const hasRole = member.roles.cache.has(selectedRoleId);
|
||||
|
||||
if (category.exclusive) {
|
||||
const options: any[] = client.DB.all('SELECT * FROM role_options WHERE category_id = ?', category.id);
|
||||
for (const opt of options) {
|
||||
if (opt.role_id !== selectedRoleId && member.roles.cache.has(opt.role_id)) {
|
||||
await member.roles.remove(opt.role_id);
|
||||
}
|
||||
}
|
||||
await member.roles.add(selectedRoleId);
|
||||
await interaction.reply({
|
||||
content: `Du hast jetzt die Rolle ${option.emoji ? option.emoji + ' ' : ''}${discordRole.name}!`,
|
||||
flags: [MessageFlags.Ephemeral]
|
||||
});
|
||||
} else {
|
||||
if (hasRole) {
|
||||
await member.roles.remove(selectedRoleId);
|
||||
await interaction.reply({
|
||||
content: `Die Rolle ${option.emoji ? option.emoji + ' ' : ''}${discordRole.name} wurde entfernt.`,
|
||||
flags: [MessageFlags.Ephemeral]
|
||||
});
|
||||
} else {
|
||||
const userRoles = member.roles.cache.filter((r: any) => !r.managed && r.id !== guild.id).size;
|
||||
if (category.max_roles > 0 && userRoles >= category.max_roles) {
|
||||
await interaction.reply({
|
||||
content: `Du kannst maximal ${category.max_roles} Rollen aus dieser Kategorie haben.`,
|
||||
flags: [MessageFlags.Ephemeral]
|
||||
});
|
||||
return;
|
||||
}
|
||||
await member.roles.add(selectedRoleId);
|
||||
await interaction.reply({
|
||||
content: `Du hast jetzt die Rolle ${option.emoji ? option.emoji + ' ' : ''}${discordRole.name}!`,
|
||||
flags: [MessageFlags.Ephemeral]
|
||||
});
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!interaction.isChatInputCommand()) return;
|
||||
|
||||
const command = client.commands.get(interaction.commandName);
|
||||
|
||||
Reference in New Issue
Block a user