Skip to content

Commit

Permalink
chore: Add autocomplete support for play command and handle autocompl…
Browse files Browse the repository at this point in the history
…etion response
  • Loading branch information
Fyphen1223 committed May 12, 2024
1 parent b29f2e9 commit 8dbaf74
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 38 deletions.
3 changes: 3 additions & 0 deletions commands/music/play.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
95 changes: 57 additions & 38 deletions events/interactionCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
},
Expand Down

0 comments on commit 8dbaf74

Please sign in to comment.