Abiru Ekanayakaツ
Abiru Ekanayakaツ
DIAdiscord.js - Imagine an app
Created by Abiru Ekanayakaツ on 11/26/2023 in #djs-questions
Why isn't the autocomplete working the autocomplete function isn't even getting called.
Why isn't the autocomplete working the autocomplete function isn't even getting called. Code:
const { ApplicationCommandOptionType, EmbedBuilder } = require("discord.js");
const formatDuration = require("../../../structures/FormatDuration.js");

module.exports = {
name: "play",
description: "Play your favorite songs.",
category: "Music",
options: [
{
name: "query",
description: "Provide song name or url. (Supports YouTube, SoundCloud, Deezer and Spotify.)",
type: ApplicationCommandOptionType.String,
required: true,
autocomplete: true, // Add autocomplete property for the 'query' option
},
],
permissions: {
bot: ["Speak", "Connect"],
channel: ["Speak", "Connect"],
user: [],
},
settings: {
inVc: true,
sameVc: false,
player: false,
current: false,
owner: false,
premium: false,
},
autocomplete: async (client, interaction) => {
console.log('Autocomplete function called!');
let query = await interaction.options.getString('query') || " ";
if (query.includes("youtu") || query.includes("youtube") || query.includes("youtu.be")) return;
let max = 7;
const result = await client.poru.resolve(query, "youtube");
const { tracks } = result;
const trackd = tracks.slice(0, max);

let results = trackd.map((track) => `${track.info.title}`);
await interaction.respond(
results.map(choice => ({ name: choice, value: choice })),
);
},

run: async (client, interaction, player) => {
await interaction.deferReply({ ephemeral: false });

const song = interaction.options.getString("query");

const embed = new EmbedBuilder().setColor(client.color);

if (player && interaction.member.voice.channelId !== interaction.guild.members.me.voice.channelId) {
embed.setDescription(`<:icons8x128:1177502387863294042> | You must be on the same voice channel as mine to use this command.`).setTimestamp();

return interaction.editReply({ embeds: [embed] });
}

const res = await client.poru.resolve({ query: song, requester: interaction.user });
const { loadType, tracks, playlistInfo } = res;

if (loadType === "LOAD_FAILED" || loadType === "NO_MATCHES") {
embed.setDescription(`<:icons8x128:1177502387863294042> | Song was not found or Failed to load song!`);

return interaction.editReply({ embeds: [embed] });
}

if (!player) {
player = await client.poru.createConnection({
guildId: interaction.guild.id,
voiceChannel: interaction.member.voice.channel.id,
textChannel: interaction.channel.id,
deaf: true,
});
}

if (player.state !== "CONNECTED") player.connect();

if (loadType === "PLAYLIST_LOADED") {
for (const track of tracks) {
player.queue.add(track);
}

embed.setDescription(`<:icons8tick128:1177501732914339840> | **[${playlistInfo.name}](${song})** • \`${tracks.length}\` tracks • ${interaction.user}`);

if (!player.isPlaying && !player.isPaused) player.play();
} else if (loadType === "SEARCH_RESULT" || loadType === "TRACK_LOADED") {
const track = tracks[0];

player.queue.add(track);

embed.setDescription(
`<:icons8tick128:1177501732914339840> | **[${track.info.title ? track.info.title : "Unknown"}](${track.info.uri})** • \`${
track.info.isStream ? "LIVE" : formatDuration(track.info.length)
}\` • ${interaction.user}`,
);

if (!player.isPlaying && !player.isPaused) player.play();
}

await interaction.editReply({ embeds: [embed] });
},
};
const { ApplicationCommandOptionType, EmbedBuilder } = require("discord.js");
const formatDuration = require("../../../structures/FormatDuration.js");

module.exports = {
name: "play",
description: "Play your favorite songs.",
category: "Music",
options: [
{
name: "query",
description: "Provide song name or url. (Supports YouTube, SoundCloud, Deezer and Spotify.)",
type: ApplicationCommandOptionType.String,
required: true,
autocomplete: true, // Add autocomplete property for the 'query' option
},
],
permissions: {
bot: ["Speak", "Connect"],
channel: ["Speak", "Connect"],
user: [],
},
settings: {
inVc: true,
sameVc: false,
player: false,
current: false,
owner: false,
premium: false,
},
autocomplete: async (client, interaction) => {
console.log('Autocomplete function called!');
let query = await interaction.options.getString('query') || " ";
if (query.includes("youtu") || query.includes("youtube") || query.includes("youtu.be")) return;
let max = 7;
const result = await client.poru.resolve(query, "youtube");
const { tracks } = result;
const trackd = tracks.slice(0, max);

let results = trackd.map((track) => `${track.info.title}`);
await interaction.respond(
results.map(choice => ({ name: choice, value: choice })),
);
},

run: async (client, interaction, player) => {
await interaction.deferReply({ ephemeral: false });

const song = interaction.options.getString("query");

const embed = new EmbedBuilder().setColor(client.color);

if (player && interaction.member.voice.channelId !== interaction.guild.members.me.voice.channelId) {
embed.setDescription(`<:icons8x128:1177502387863294042> | You must be on the same voice channel as mine to use this command.`).setTimestamp();

return interaction.editReply({ embeds: [embed] });
}

const res = await client.poru.resolve({ query: song, requester: interaction.user });
const { loadType, tracks, playlistInfo } = res;

if (loadType === "LOAD_FAILED" || loadType === "NO_MATCHES") {
embed.setDescription(`<:icons8x128:1177502387863294042> | Song was not found or Failed to load song!`);

return interaction.editReply({ embeds: [embed] });
}

if (!player) {
player = await client.poru.createConnection({
guildId: interaction.guild.id,
voiceChannel: interaction.member.voice.channel.id,
textChannel: interaction.channel.id,
deaf: true,
});
}

if (player.state !== "CONNECTED") player.connect();

if (loadType === "PLAYLIST_LOADED") {
for (const track of tracks) {
player.queue.add(track);
}

embed.setDescription(`<:icons8tick128:1177501732914339840> | **[${playlistInfo.name}](${song})** • \`${tracks.length}\` tracks • ${interaction.user}`);

if (!player.isPlaying && !player.isPaused) player.play();
} else if (loadType === "SEARCH_RESULT" || loadType === "TRACK_LOADED") {
const track = tracks[0];

player.queue.add(track);

embed.setDescription(
`<:icons8tick128:1177501732914339840> | **[${track.info.title ? track.info.title : "Unknown"}](${track.info.uri})** • \`${
track.info.isStream ? "LIVE" : formatDuration(track.info.length)
}\` • ${interaction.user}`,
);

if (!player.isPlaying && !player.isPaused) player.play();
}

await interaction.editReply({ embeds: [embed] });
},
};
31 replies