64 lines
2.1 KiB
JavaScript
64 lines
2.1 KiB
JavaScript
const { SlashCommandBuilder, ActionRowBuilder, RoleSelectMenuBuilder, ComponentType } = require('discord.js');
|
|
const { readDb, writeDb } = require('../../backend/db.js');
|
|
|
|
module.exports = {
|
|
name: 'setup-autorole',
|
|
description: 'Interactively set up the autorole for this server.',
|
|
enabled: true,
|
|
builder: new SlashCommandBuilder()
|
|
.setName('setup-autorole')
|
|
.setDescription('Interactively set up the autorole for this server.'),
|
|
async execute(interaction) {
|
|
const db = readDb();
|
|
const guildId = interaction.guildId;
|
|
|
|
if (!db[guildId]) {
|
|
db[guildId] = {};
|
|
}
|
|
|
|
const roleSelect = new RoleSelectMenuBuilder()
|
|
.setCustomId('autorole_role_select')
|
|
.setPlaceholder('Select the role to assign on join.');
|
|
|
|
const row = new ActionRowBuilder().addComponents(roleSelect);
|
|
|
|
const roleReply = await interaction.reply({
|
|
content: 'Please select the role you want to automatically assign to new members.',
|
|
components: [row],
|
|
flags: 64,
|
|
});
|
|
|
|
try {
|
|
const roleConfirmation = await roleReply.awaitMessageComponent({
|
|
componentType: ComponentType.RoleSelect,
|
|
time: 60000,
|
|
});
|
|
|
|
const roleId = roleConfirmation.values[0];
|
|
const role = interaction.guild.roles.cache.get(roleId);
|
|
|
|
if (role.managed || role.position >= interaction.guild.members.me.roles.highest.position) {
|
|
await roleConfirmation.update({
|
|
content: `I cannot assign the role **${role.name}** because it is managed by an integration or is higher than my highest role. Please select another role.`,
|
|
components: [],
|
|
});
|
|
return;
|
|
}
|
|
|
|
db[guildId].autorole = {
|
|
enabled: true,
|
|
roleId: roleId,
|
|
};
|
|
writeDb(db);
|
|
|
|
await roleConfirmation.update({
|
|
content: `Autorole setup complete! New members will be assigned the **${role.name}** role.`,
|
|
components: [],
|
|
});
|
|
} catch (error) {
|
|
console.error('Error during autorole setup:', error);
|
|
await interaction.editReply({ content: 'Configuration timed out or an error occurred.', components: [] });
|
|
}
|
|
},
|
|
};
|