Closed chaos3326 closed 2 years ago
Can you send your code?
It is pretty much straightforward to know that this isnt a bug plus it is neither a problem caused by discord-player. You are trying to reply to an unknown interaction in your command-error handler (src\events\client\interactionCreate.js
) file
Here's the code in my play.js
file:
const {
SlashCommandBuilder,
EmbedBuilder,
// ActionRowBuilder,
// ButtonBuilder,
// ButtonStyle,
} = require("discord.js");
const { getVoiceConnection } = require("@discordjs/voice");
const { QueryType } = require("discord-player");
module.exports = {
data: new SlashCommandBuilder()
.setName("play")
.setDescription("play a song from YouTube.")
.addStringOption((option) =>
option
.setName("input")
.setDescription("search keywords, or video, playlist link")
.setRequired(true)
),
async execute(interaction, client) {
// Make sure the user is inside a connectable voice channel
if (!interaction.member.voice.channel)
return await interaction.reply(
"You need to be in a Voice Channel to play a song."
);
const mychannel = getVoiceConnection(interaction.guild.id)?.joinConfig
.channelId;
if (mychannel && interaction.member.voice.channelId !== mychannel)
return await interaction.reply({
content: "You are not in my voice channel!",
ephemeral: true,
});
// Create a play queue for the server
const queue = await client.player.createQueue(interaction.guild);
// Wait until you are connected to the channel
try {
if (!queue.connection)
await queue.connect(interaction.member.voice.channel);
} catch {
queue.destroy();
return await interaction.reply({
content: "Could not join your voice channel!",
ephemeral: true,
});
}
let embed = new EmbedBuilder();
// Search for the song using the discord-player
let input = interaction.options.getString("input");
const result = await client.player.search(input, {
requestedBy: interaction.user,
searchEngine: QueryType.AUTO,
});
// finish if no tracks were found
console.log(queue);
if (result.tracks.length === 0) return interaction.editReply("No results");
// if it's not a playlist
if (!result.playlist) {
if (result.tracks.length === 1) {
const song = result.tracks[0];
await queue.addTrack(song);
embed
.setAuthor({ name: song.author })
.setDescription(
`**[${song.title}](${song.url} "${song.title}")** has been added to the Queue`
)
.setThumbnail(song.thumbnail)
.setFooter({ text: `Duration: ${song.duration}` });
} else {
const message = await Promise.all(
result.tracks.map(async (track, index) => {
if (index >= 10) return "";
return `**.[${track.title}](${track.url} )** from channel **${track.author}**`;
})
);
embed
.setAuthor({
name: interaction.member.nickname || interaction.user.tag,
iconURL: interaction.member.displayAvatarURL(),
})
.setDescription(
`**Please select a songs.**\n` +
message.filter((x) => x.length > 0).join("\n")
);
}
} else {
const message = await Promise.all(
result.tracks.map(async (track, index) => {
await queue.addTrack(track);
if (index >= 10) return "";
return `**.[${track.title}](${track.url} )** from channel **${track.author}**`;
})
);
embed
.setAuthor({
name: interaction.member.nickname || interaction.user.tag,
iconURL: interaction.member.displayAvatarURL(),
})
.setDescription(
`**Added songs** from **[${result.playlist.title}](${result.playlist.url} )** playlist:\n` +
message.filter((x) => x.length > 0).join("\n") +
(result.tracks.length > 10
? `\n*and ${result.tracks.length - 10} more*`
: ``)
);
console.log(result);
}
// Play the song
if (!queue.playing) await queue.play();
// Respond with the embed containing information about the player
await interaction.reply({
embeds: [embed],
});
},
};
Sorry for being so dumb. I found the issue myself.
It happened because I used interaction.editReply
(line 61) but there is no reply yet for this interaction, so it crashed the bot.
I just learned that discord only gives the bot 3s to do a task. If it needs more, it need defer reply. If the interaction has defer reply, it will use editReply instead of reply.
The bot worked perfectly, until it won't. When I tried to add a very long video (like 3 hours or longer) or sometimes it happened to short video when the queue is already long enough, the bot will crash with the following error in the console:
I need support to handle this bug, like... this will add nothing to the queue instead of crash the bot. Thank you very much for readding this message.