TheMonDon
TheMonDon
DIdiscord.js - Imagine ❄
Created by TheMonDon on 1/19/2025 in #djs-questions
Autocomplete Unknown Interaction
I think this is the actual answer to my question, I timed the autocomplete interaction and its taking up to 9 seconds to complete, im guessing my internet is the problem then
33 replies
DIdiscord.js - Imagine ❄
Created by TheMonDon on 1/19/2025 in #djs-questions
Autocomplete Unknown Interaction
Okay thanks
33 replies
DIdiscord.js - Imagine ❄
Created by TheMonDon on 1/19/2025 in #djs-questions
Autocomplete Unknown Interaction
yeah
33 replies
DIdiscord.js - Imagine ❄
Created by TheMonDon on 1/19/2025 in #djs-questions
Autocomplete Unknown Interaction
discord-player
33 replies
DIdiscord.js - Imagine ❄
Created by TheMonDon on 1/19/2025 in #djs-questions
Autocomplete Unknown Interaction
Autocomplete code:
exports.autoComplete = async (interaction) => {
try {
const song = interaction.options.getString('song');
if (!song || song.trim().length === 0) {
return interaction.respond([]);
}

const player = useMainPlayer();

const data = await player.search(song, { requestedBy: interaction.user });

if (!data.hasTracks()) {
return interaction.respond([]);
}

const results = data.tracks
.filter((track) => track.url.length < 100)
.slice(0, 10)
.map((track) => ({
name: track.title.slice(0, 100),
value: track.url,
}));

return interaction.respond(results);
} catch (error) {
interaction.client.logger.error('Error handling autocomplete:', error);

return interaction.respond([]).catch(() => {});
}
};
exports.autoComplete = async (interaction) => {
try {
const song = interaction.options.getString('song');
if (!song || song.trim().length === 0) {
return interaction.respond([]);
}

const player = useMainPlayer();

const data = await player.search(song, { requestedBy: interaction.user });

if (!data.hasTracks()) {
return interaction.respond([]);
}

const results = data.tracks
.filter((track) => track.url.length < 100)
.slice(0, 10)
.map((track) => ({
name: track.title.slice(0, 100),
value: track.url,
}));

return interaction.respond(results);
} catch (error) {
interaction.client.logger.error('Error handling autocomplete:', error);

return interaction.respond([]).catch(() => {});
}
};
music code:
case 'play': {
if (!interaction.member.voice.channel) {
return interaction.editReply('You must be in a voice channel to play music.');
}
if (
interaction.guild.members.me.voice.channel &&
interaction.member.voice.channel.id !== interaction.guild.members.me.voice.channel.id
) {
return interaction.editReply('You have to be in the same voice channel as the bot to play music');
}

const query = interaction.options.get('song').value;

try {
const { track } = await player.play(interaction.member.voice.channel, query, {
requestedBy: interaction.user,
nodeOptions: {
metadata: interaction,
selfDead: true,
leaveOnStop: true,
leaveOnEnd: false,
leaveOnEmpty: false,
},
});

if (!track) return interaction.editReply('No tracks found.');

return interaction.editReply('Music Started');
} catch (e) {
return interaction.editReply(`Something went wrong: ${e}`);
}
}
case 'play': {
if (!interaction.member.voice.channel) {
return interaction.editReply('You must be in a voice channel to play music.');
}
if (
interaction.guild.members.me.voice.channel &&
interaction.member.voice.channel.id !== interaction.guild.members.me.voice.channel.id
) {
return interaction.editReply('You have to be in the same voice channel as the bot to play music');
}

const query = interaction.options.get('song').value;

try {
const { track } = await player.play(interaction.member.voice.channel, query, {
requestedBy: interaction.user,
nodeOptions: {
metadata: interaction,
selfDead: true,
leaveOnStop: true,
leaveOnEnd: false,
leaveOnEmpty: false,
},
});

if (!track) return interaction.editReply('No tracks found.');

return interaction.editReply('Music Started');
} catch (e) {
return interaction.editReply(`Something went wrong: ${e}`);
}
}
33 replies
DIdiscord.js - Imagine ❄
Created by TheMonDon on 7/16/2023 in #djs-questions
What is the difference between autocomplete and string input options?
Alright thanks
9 replies
DIdiscord.js - Imagine ❄
Created by TheMonDon on 7/16/2023 in #djs-questions
What is the difference between autocomplete and string input options?
Its for a bot builder program so it makes more sense, but usually I would understand
9 replies
DIdiscord.js - Imagine ❄
Created by TheMonDon on 7/16/2023 in #djs-questions
What is the difference between autocomplete and string input options?
If my bot deploys commands everytime it starts up is it technically any different compared to autocomplete?
9 replies