Add 'Keine' option and toggle hint for role selection
All checks were successful
Auto Build and Push Docker Image / build (push) Successful in 6s
All checks were successful
Auto Build and Push Docker Image / build (push) Successful in 6s
This commit is contained in:
@@ -19,18 +19,27 @@ async function updateRoleMessage(client: any, category: any) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const selectMenu = new StringSelectMenuBuilder()
|
const roleOptions = options.map((opt: any) =>
|
||||||
.setCustomId(`role_select_${category.category_name}`)
|
|
||||||
.setPlaceholder('Wähle eine Rolle...')
|
|
||||||
.addOptions(options.map((opt: any) =>
|
|
||||||
new StringSelectMenuOptionBuilder()
|
new StringSelectMenuOptionBuilder()
|
||||||
.setLabel(opt.label.replace(/^[^\s]+\s/, ''))
|
.setLabel(opt.label.replace(/^[^\s]+\s/, ''))
|
||||||
.setValue(opt.role_id)
|
.setValue(opt.role_id)
|
||||||
.setEmoji(opt.emoji || '')
|
.setEmoji(opt.emoji || '')
|
||||||
));
|
);
|
||||||
|
|
||||||
|
roleOptions.push(
|
||||||
|
new StringSelectMenuOptionBuilder()
|
||||||
|
.setLabel('Keine')
|
||||||
|
.setValue(`remove_${category.id}`)
|
||||||
|
.setEmoji('❌')
|
||||||
|
);
|
||||||
|
|
||||||
|
const selectMenu = new StringSelectMenuBuilder()
|
||||||
|
.setCustomId(`role_select_${category.category_name}`)
|
||||||
|
.setPlaceholder('Wähle eine Rolle...')
|
||||||
|
.addOptions(roleOptions);
|
||||||
|
|
||||||
await message.edit({
|
await message.edit({
|
||||||
content: `**${category.category_name}**\nWähle unten eine Rolle aus:`,
|
content: `**${category.category_name}**\nWähle unten eine Rolle aus:\n*Klicke erneut auf eine Rolle um sie zu entfernen.*`,
|
||||||
components: [{ type: ComponentType.ActionRow, components: [selectMenu] }]
|
components: [{ type: ComponentType.ActionRow, components: [selectMenu] }]
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ export default {
|
|||||||
|
|
||||||
if (customId.startsWith('role_select_')) {
|
if (customId.startsWith('role_select_')) {
|
||||||
const categoryName = customId.replace('role_select_', '');
|
const categoryName = customId.replace('role_select_', '');
|
||||||
const selectedRoleId = interaction.values[0];
|
const selectedValue = interaction.values[0];
|
||||||
const member = interaction.member;
|
const member = interaction.member;
|
||||||
const guild = interaction.guild;
|
const guild = interaction.guild;
|
||||||
|
|
||||||
@@ -23,10 +23,33 @@ export default {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (selectedValue.startsWith('remove_')) {
|
||||||
|
const options: any[] = client.DB.all('SELECT * FROM role_options WHERE category_id = ?', category.id);
|
||||||
|
let removedCount = 0;
|
||||||
|
for (const opt of options) {
|
||||||
|
if (member.roles.cache.has(opt.role_id)) {
|
||||||
|
await member.roles.remove(opt.role_id);
|
||||||
|
removedCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (removedCount > 0) {
|
||||||
|
await interaction.reply({
|
||||||
|
content: `Alle Rollen aus "${categoryName}" wurden entfernt.`,
|
||||||
|
flags: [MessageFlags.Ephemeral]
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
await interaction.reply({
|
||||||
|
content: `Du hast keine Rollen aus "${categoryName}".`,
|
||||||
|
flags: [MessageFlags.Ephemeral]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const option: any = client.DB.get(
|
const option: any = client.DB.get(
|
||||||
'SELECT * FROM role_options WHERE category_id = ? AND role_id = ?',
|
'SELECT * FROM role_options WHERE category_id = ? AND role_id = ?',
|
||||||
category.id,
|
category.id,
|
||||||
selectedRoleId
|
selectedValue
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!option) {
|
if (!option) {
|
||||||
@@ -34,29 +57,29 @@ export default {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const discordRole = guild.roles.cache.get(selectedRoleId);
|
const discordRole = guild.roles.cache.get(selectedValue);
|
||||||
if (!discordRole) {
|
if (!discordRole) {
|
||||||
await interaction.reply({ content: 'Diese Rolle existiert nicht mehr.', flags: [MessageFlags.Ephemeral] });
|
await interaction.reply({ content: 'Diese Rolle existiert nicht mehr.', flags: [MessageFlags.Ephemeral] });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const hasRole = member.roles.cache.has(selectedRoleId);
|
const hasRole = member.roles.cache.has(selectedValue);
|
||||||
|
|
||||||
if (category.exclusive) {
|
if (category.exclusive) {
|
||||||
const options: any[] = client.DB.all('SELECT * FROM role_options WHERE category_id = ?', category.id);
|
const options: any[] = client.DB.all('SELECT * FROM role_options WHERE category_id = ?', category.id);
|
||||||
for (const opt of options) {
|
for (const opt of options) {
|
||||||
if (opt.role_id !== selectedRoleId && member.roles.cache.has(opt.role_id)) {
|
if (opt.role_id !== selectedValue && member.roles.cache.has(opt.role_id)) {
|
||||||
await member.roles.remove(opt.role_id);
|
await member.roles.remove(opt.role_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await member.roles.add(selectedRoleId);
|
await member.roles.add(selectedValue);
|
||||||
await interaction.reply({
|
await interaction.reply({
|
||||||
content: `Du hast jetzt die Rolle ${option.emoji ? option.emoji + ' ' : ''}${discordRole.name}!`,
|
content: `Du hast jetzt die Rolle ${option.emoji ? option.emoji + ' ' : ''}${discordRole.name}!`,
|
||||||
flags: [MessageFlags.Ephemeral]
|
flags: [MessageFlags.Ephemeral]
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
if (hasRole) {
|
if (hasRole) {
|
||||||
await member.roles.remove(selectedRoleId);
|
await member.roles.remove(selectedValue);
|
||||||
await interaction.reply({
|
await interaction.reply({
|
||||||
content: `Die Rolle ${option.emoji ? option.emoji + ' ' : ''}${discordRole.name} wurde entfernt.`,
|
content: `Die Rolle ${option.emoji ? option.emoji + ' ' : ''}${discordRole.name} wurde entfernt.`,
|
||||||
flags: [MessageFlags.Ephemeral]
|
flags: [MessageFlags.Ephemeral]
|
||||||
@@ -70,7 +93,7 @@ export default {
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await member.roles.add(selectedRoleId);
|
await member.roles.add(selectedValue);
|
||||||
await interaction.reply({
|
await interaction.reply({
|
||||||
content: `Du hast jetzt die Rolle ${option.emoji ? option.emoji + ' ' : ''}${discordRole.name}!`,
|
content: `Du hast jetzt die Rolle ${option.emoji ? option.emoji + ' ' : ''}${discordRole.name}!`,
|
||||||
flags: [MessageFlags.Ephemeral]
|
flags: [MessageFlags.Ephemeral]
|
||||||
|
|||||||
Reference in New Issue
Block a user