No focused option for autocomplete interaction

Hey I get the following error. How can I handle this.
TypeError [AutocompleteInteractionOptionNoFocusedOption]: No focused option for autocomplete interaction.
TypeError [AutocompleteInteractionOptionNoFocusedOption]: No focused option for autocomplete interaction.
7 Replies
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Nlmyr
NlmyrOP3y ago
[email protected] D:\Coding\xyz └── [email protected] v17.4.0
node:events:498
throw er; // Unhandled 'error' event
^

TypeError [AutocompleteInteractionOptionNoFocusedOption]: No focused option for autocomplete interaction.
at CommandInteractionOptionResolver.getFocused (M:\yPath\node_modules\discord.js\src\structures\CommandInteractionOptionResolver.js:276:31)
at Client.<anonymous> (M:\yPath\utils\UtilClientHandler.js:113:48)
at Client.emit (node:events:532:35)
at InteractionCreateAction.handle (M:\yPath\node_modules\discord.js\src\client\actions\InteractionCreate.js:81:12)
at Object.module.exports [as INTERACTION_CREATE] (M:\yPath\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (M:\yPath\node_modules\discord.js\src\client\websocket\WebSocketManager.js:352:31)
at WebSocketShard.onPacket (M:\yPath\node_modules\discord.js\src\client\websocket\WebSocketShard.js:481:22)
at WebSocketShard.onMessage (M:\yPath\node_modules\discord.js\src\client\websocket\WebSocketShard.js:321:10)
at WebSocket.onMessage (M:\yPath\node_modules\ws\lib\event-target.js:199:18)
at WebSocket.emit (node:events:520:28)
Emitted 'error' event on Client instance at:
at emitUnhandledRejectionOrErr (node:events:381:10)
at processTicksAndRejections (node:internal/process/task_queues:85:21) {
code: 'AutocompleteInteractionOptionNoFocusedOption'
}
node:events:498
throw er; // Unhandled 'error' event
^

TypeError [AutocompleteInteractionOptionNoFocusedOption]: No focused option for autocomplete interaction.
at CommandInteractionOptionResolver.getFocused (M:\yPath\node_modules\discord.js\src\structures\CommandInteractionOptionResolver.js:276:31)
at Client.<anonymous> (M:\yPath\utils\UtilClientHandler.js:113:48)
at Client.emit (node:events:532:35)
at InteractionCreateAction.handle (M:\yPath\node_modules\discord.js\src\client\actions\InteractionCreate.js:81:12)
at Object.module.exports [as INTERACTION_CREATE] (M:\yPath\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (M:\yPath\node_modules\discord.js\src\client\websocket\WebSocketManager.js:352:31)
at WebSocketShard.onPacket (M:\yPath\node_modules\discord.js\src\client\websocket\WebSocketShard.js:481:22)
at WebSocketShard.onMessage (M:\yPath\node_modules\discord.js\src\client\websocket\WebSocketShard.js:321:10)
at WebSocket.onMessage (M:\yPath\node_modules\ws\lib\event-target.js:199:18)
at WebSocket.emit (node:events:520:28)
Emitted 'error' event on Client instance at:
at emitUnhandledRejectionOrErr (node:events:381:10)
at processTicksAndRejections (node:internal/process/task_queues:85:21) {
code: 'AutocompleteInteractionOptionNoFocusedOption'
}
monbrey
monbrey3y ago
can you show your code to go with it?
Nlmyr
NlmyrOP3y ago
async initAutocompletion() {
this.client.on(Events.InteractionCreate, async (interaction) => {
if (!interaction.isAutocomplete()) return;
if (interaction.commandName == "streamer") {
const focusValue = interaction.options.getFocused();

const streamers = await ModelTwitchStreamer.find({
streamer: { $regex: focusValue, $options: "i" },
}).limit(25);

const streamerMap = streamers.map((streamer) => {
return {
name: streamer.streamer,
value: streamer.streamer,
};
});

interaction.respond(streamerMap);
}
});
}
async initAutocompletion() {
this.client.on(Events.InteractionCreate, async (interaction) => {
if (!interaction.isAutocomplete()) return;
if (interaction.commandName == "streamer") {
const focusValue = interaction.options.getFocused();

const streamers = await ModelTwitchStreamer.find({
streamer: { $regex: focusValue, $options: "i" },
}).limit(25);

const streamerMap = streamers.map((streamer) => {
return {
name: streamer.streamer,
value: streamer.streamer,
};
});

interaction.respond(streamerMap);
}
});
}
case "remove": {
const username = interaction.options.getString("username");
console.log(username);
break;
}
case "remove": {
const username = interaction.options.getString("username");
console.log(username);
break;
}
@monbrey Slash Command Data
{
name: "remove",
description: "Remove a streamer from the streamer list",
type: ApplicationCommandOptionType.Subcommand,
options: [
{
name: "username",
description: "the username of the streamer",
type: ApplicationCommandOptionType.String,
required: true,
autocomplete: true,
},
],
},
{
name: "remove",
description: "Remove a streamer from the streamer list",
type: ApplicationCommandOptionType.Subcommand,
options: [
{
name: "username",
description: "the username of the streamer",
type: ApplicationCommandOptionType.String,
required: true,
autocomplete: true,
},
],
},
monbrey
monbrey3y ago
This event isnt filtering only autocomplete interactions Its going to try to get a focused option on every time of interaction, including buttons, slash commands etc
Nlmyr
NlmyrOP3y ago
oh i see i forgot that i fixed that thank you @monbrey have a nice day
monbrey
monbrey3y ago
np
Want results from more Discord servers?
Add your server