Major upgrades and architectural improvements: - Upgrade Discord.js from v12 to v14.21.0 - Upgrade Node.js from 14 to 22 LTS - Switch to pnpm package manager - Complete rewrite with modern Discord API patterns New Features: - Hybrid command system: prefix commands + slash commands - /sfx slash command with autocomplete for sound discovery - Modern @discordjs/voice integration for audio - Improved voice connection management - Enhanced logging for SFX commands - Multi-stage Docker build for optimized images Technical Improvements: - Modular architecture with services and command handlers - Proper intent management for Discord gateway - Better error handling and logging - Hot-reload capability maintained - Environment variable support - Optimized Docker container with Alpine Linux Breaking Changes: - Moved main entry from index.js to src/index.js - Updated configuration structure for v14 compatibility - Replaced deprecated voice APIs with @discordjs/voice - Updated audio dependencies (opus, ffmpeg) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
74 lines
2.5 KiB
JavaScript
74 lines
2.5 KiB
JavaScript
module.exports = {
|
|
name: 'role',
|
|
description: 'Add or remove allowed roles',
|
|
|
|
async execute(message, args, guildConfig) {
|
|
// Check if there are allowed roles configured
|
|
if (!guildConfig.allowedRolesForRequest || guildConfig.allowedRolesForRequest.length === 0) {
|
|
return message.reply('No roles are currently allowed to be added/removed by members.');
|
|
}
|
|
|
|
// Show usage if no arguments
|
|
if (args.length === 0) {
|
|
return message.reply(
|
|
`Usage: ${guildConfig.prefix}role {add|remove} {${guildConfig.allowedRolesForRequest}}`
|
|
);
|
|
}
|
|
|
|
const action = args[0]?.toLowerCase();
|
|
const roleName = args.slice(1).join(' ');
|
|
|
|
// Validate action
|
|
if (!['add', 'remove'].includes(action)) {
|
|
return message.reply(
|
|
`You must use add/remove after the role command! *e.g. ${guildConfig.prefix}role add <rolename>*`
|
|
);
|
|
}
|
|
|
|
// Validate role name
|
|
if (!roleName) {
|
|
return message.reply(
|
|
`Usage: ${guildConfig.prefix}role {add|remove} {${guildConfig.allowedRolesForRequest}}`
|
|
);
|
|
}
|
|
|
|
// Check if role is in the allowed list
|
|
const allowedRoles = guildConfig.allowedRolesForRequest.split('|');
|
|
const roleRegex = new RegExp(guildConfig.allowedRolesForRequest, 'i');
|
|
|
|
if (!roleRegex.test(roleName)) {
|
|
return message.reply(
|
|
`**${roleName}** is not a valid role name! The roles allowed for request are: ${allowedRoles.join(', ')}`
|
|
);
|
|
}
|
|
|
|
// Find the role in the guild (case-sensitive search)
|
|
const role = message.guild.roles.cache.find(r =>
|
|
r.name.toLowerCase() === roleName.toLowerCase()
|
|
);
|
|
|
|
if (!role) {
|
|
return message.reply(`${roleName} is not a role on this server!`);
|
|
}
|
|
|
|
try {
|
|
if (action === 'add') {
|
|
await message.member.roles.add(role, 'User requested');
|
|
await message.react('👍');
|
|
console.log(`Added role ${role.name} to ${message.author.username}`);
|
|
} else if (action === 'remove') {
|
|
await message.member.roles.remove(role, 'User requested');
|
|
await message.react('👍');
|
|
console.log(`Removed role ${role.name} from ${message.author.username}`);
|
|
}
|
|
} catch (error) {
|
|
console.error(`Error managing role ${role.name}:`, error);
|
|
await message.react('⚠️');
|
|
|
|
// Send error message if we can't react
|
|
if (!message.reactions.cache.has('⚠️')) {
|
|
await message.reply('I encountered an error managing that role. Make sure I have the proper permissions!');
|
|
}
|
|
}
|
|
}
|
|
}; |