Unsuccessful implementation of autocomplete with subcommands

Here is the abridged code command file
module.exports = {
data: new SlashCommandBuilder().setName('getnextevent')
.setDescription('get the next event for the indicated team')
.addSubcommand(subcommand =>
subcommand.setName('nba').setDescription('National Basketball Association')
.addStringOption(option =>
option.setName('team').setDescription('the name of the team').setRequired(true).setAutocomplete(true))),
async autocomplete(interaction) {
const focusedValue = interaction.options.getFocused(true);
const choices = ['Popular Topics: Threads', 'Sharding: Getting started', 'Library: Voice Connections', 'Interactions: Replying to slash commands', 'Popular Topics: Embed preview'];
const filtered = choices.filter(choice => choice.startsWith(focusedValue));
await interaction.respond(
filtered.map(choice => ({ name: choice, value: choice })),
);
}
}
module.exports = {
data: new SlashCommandBuilder().setName('getnextevent')
.setDescription('get the next event for the indicated team')
.addSubcommand(subcommand =>
subcommand.setName('nba').setDescription('National Basketball Association')
.addStringOption(option =>
option.setName('team').setDescription('the name of the team').setRequired(true).setAutocomplete(true))),
async autocomplete(interaction) {
const focusedValue = interaction.options.getFocused(true);
const choices = ['Popular Topics: Threads', 'Sharding: Getting started', 'Library: Voice Connections', 'Interactions: Replying to slash commands', 'Popular Topics: Embed preview'];
const filtered = choices.filter(choice => choice.startsWith(focusedValue));
await interaction.respond(
filtered.map(choice => ({ name: choice, value: choice })),
);
}
}
index.js
if (interaction.isAutocomplete()) {
await command.autocomplete(interaction);
} else {
await command.execute(interaction, conn);
}
if (interaction.isAutocomplete()) {
await command.autocomplete(interaction);
} else {
await command.execute(interaction, conn);
}
I have console logs in the autocomplete function that are not firing so I don't understand what is going on. In my command handler I also have a log for the interaction which is also not firing.
11 Replies
d.js toolkit
d.js toolkit10mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
Beat.
Beat.OP10mo ago
Node 20.10.0, discord version in the tag
Amgelo
Amgelo10mo ago
can you show your entire listener
Beat.
Beat.OP10mo ago
Sure one sec Its too big, give me a sec to link it somewhere
Beat.
Beat.OP10mo ago
Pastebin
autocomplete subcommand - Pastebin.com
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Amgelo
Amgelo10mo ago
No description
Amgelo
Amgelo10mo ago
there you are ignoring autocomplete interactions
Beat.
Beat.OP10mo ago
🤦‍♂️
d.js docs
d.js docs10mo ago
:method: CommandInteraction#isAutocomplete() Indicates whether this interaction is an AutocompleteInteraction
Amgelo
Amgelo10mo ago
check for that as well
Beat.
Beat.OP10mo ago
👍
Want results from more Discord servers?
Add your server