diff --git a/commands/music/play.js b/commands/music/play.js index 40d5e95..ae2540b 100644 --- a/commands/music/play.js +++ b/commands/music/play.js @@ -24,6 +24,9 @@ module.exports = { .setAutocomplete(true) .setRequired(false) ), + async autocomplete(interaction) { + // handle the autocompletion response (more on how to do that below) + }, async execute(interaction) { await interaction.deferReply(); if (!interaction.member.voice.channelId) { diff --git a/events/interactionCreate.js b/events/interactionCreate.js index 0875b61..ddb2a1f 100644 --- a/events/interactionCreate.js +++ b/events/interactionCreate.js @@ -10,49 +10,68 @@ const { Events } = require('discord.js'); module.exports = { name: Events.InteractionCreate, async execute(interaction) { - if (!interaction.isChatInputCommand()) return; + if (interaction.isChatInputCommand()) { + const command = interaction.client.commands.get( + interaction.commandName + ); - const command = interaction.client.commands.get( - interaction.commandName - ); + if (!command) { + console.error( + `No command matching ${interaction.commandName} was found.` + ); + return; + } - if (!command) { - console.error( - `No command matching ${interaction.commandName} was found.` - ); - return; - } + if (!guilds[interaction.guildId]) { + guilds[interaction.guildId] = { + locale: 'en', + config: {}, + }; + fs.writeFileSync( + './data/guilds.json', + JSON.stringify(guilds, null, 4) + ); + log.info( + `Guild ${interaction.guildId} added to guilds.json`, + config.config.log.debug, + config.config.log.saveToFile + ); + } - if (!guilds[interaction.guildId]) { - guilds[interaction.guildId] = { - locale: 'en', - config: {}, - }; - fs.writeFileSync( - './data/guilds.json', - JSON.stringify(guilds, null, 4) - ); - log.info( - `Guild ${interaction.guildId} added to guilds.json`, - config.config.log.debug, - config.config.log.saveToFile + try { + await command.execute(interaction); + } catch (error) { + console.error(error); + if (interaction.replied || interaction.deferred) { + await interaction.followUp({ + content: + 'There was an error while executing this command!', + ephemeral: true, + }); + } else { + await interaction.reply({ + content: + 'There was an error while executing this command!', + ephemeral: true, + }); + } + } + } else if (interaction.isAutocomplete()) { + const command = interaction.client.commands.get( + interaction.commandName ); - } - try { - await command.execute(interaction); - } catch (error) { - console.error(error); - if (interaction.replied || interaction.deferred) { - await interaction.followUp({ - content: 'There was an error while executing this command!', - ephemeral: true, - }); - } else { - await interaction.reply({ - content: 'There was an error while executing this command!', - ephemeral: true, - }); + if (!command) { + console.error( + `No command matching ${interaction.commandName} was found.` + ); + return; + } + + try { + await command.autocomplete(interaction); + } catch (error) { + console.error(error); } } },