From ecb5a75de1b0fe43a92f242604dd941245a7205f Mon Sep 17 00:00:00 2001 From: Wizzard Date: Sat, 17 Aug 2024 20:13:09 -0400 Subject: [PATCH] Implement aliases --- commands/help.js | 1 + commands/play.js | 1 + commands/queue.js | 1 + commands/remove.js | 1 + commands/skip.js | 1 + index.js | 7 +++++-- 6 files changed, 10 insertions(+), 2 deletions(-) diff --git a/commands/help.js b/commands/help.js index 120181a..ba796c6 100644 --- a/commands/help.js +++ b/commands/help.js @@ -3,6 +3,7 @@ const { EmbedBuilder } = require('discord.js'); module.exports = { name: 'help', description: 'List all commands or get details about a specific command', + aliases: ['h'], execute(message, args) { const { commands } = message.client; const commandsArray = Array.from(commands.values()); diff --git a/commands/play.js b/commands/play.js index 224bd37..9ba568b 100644 --- a/commands/play.js +++ b/commands/play.js @@ -8,6 +8,7 @@ const { exec, spawn } = require('child_process'); module.exports = { name: 'play', description: 'Play a song from YouTube, a URL, or an uploaded media file', + aliases: ['p'], async execute(message, args) { const fetch = await import('node-fetch').then(module => module.default); const searchQuery = args.join(' '); diff --git a/commands/queue.js b/commands/queue.js index f0b9db1..53485b0 100644 --- a/commands/queue.js +++ b/commands/queue.js @@ -4,6 +4,7 @@ const { EmbedBuilder } = require('discord.js'); module.exports = { name: 'queue', description: 'Show the current songs in queue', + aliases: ['q'], execute(message) { const queue = getQueue(message.guild.id); const currentTrack = getCurrentTrack(message.guild.id); diff --git a/commands/remove.js b/commands/remove.js index 0a3b85b..e589ea9 100644 --- a/commands/remove.js +++ b/commands/remove.js @@ -3,6 +3,7 @@ const { getQueue, removeFromQueue } = require('../utils/queueManager'); module.exports = { name: 'remove', description: 'Remove a specific song from the queue by its number', + aliases: ['rm'], execute(message, args) { const queue = getQueue(message.guild.id); const indexToRemove = parseInt(args[0], 10) - 1; diff --git a/commands/skip.js b/commands/skip.js index fea1574..58d3c46 100644 --- a/commands/skip.js +++ b/commands/skip.js @@ -3,6 +3,7 @@ const { skipTrack, getCurrentTrack, getQueue } = require('../utils/queueManager' module.exports = { name: 'skip', description: 'Skip the current track', + aliases: ['s'], execute(message) { const guildId = message.guild.id; const voiceChannel = message.member.voice.channel; diff --git a/index.js b/index.js index 04798da..acb5fa1 100644 --- a/index.js +++ b/index.js @@ -64,10 +64,13 @@ client.on('messageCreate', async message => { const args = message.content.slice(prefix.length).trim().split(/ +/); const commandName = args.shift().toLowerCase(); - if (!client.commands.has(commandName)) return; + const command = client.commands.get(commandName) || + Array.from(client.commands.values()).find(cmd => cmd.aliases && cmd.aliases.includes(commandName)); + + if (!command) return; try { - await client.commands.get(commandName).execute(message, args); + await command.execute(message, args); } catch (error) { console.error(error); message.reply('There was an error trying to execute that command!');