I am having a lot of trouble with this bug, and is almost impossible to track through error-tracking. The track begins, and as soon as it begins, it will end (only sometimes). This is not track-specific and can happen at seemingly random times when the /play command executes. Any help?
This is /play command.
import { PlayerMetadata } from '#bot/player/PlayerMetadata';
import { fetchPlayerOptions } from '#bot/player/playerOptions';
import { EmbedGenerator } from '#bot/utils/EmbedGenerator';
import { ApplicationCommandOptionType } from 'discord.js';
import { useMainPlayer, QueueRepeatMode } from 'discord-player';
export const data = {
name: 'play',
description: 'Play a song',
options: [
{
name: 'query',
description: 'The track or playlist to play [query or url]. Playlist ID must be prefixed with "playlist:"',
type: ApplicationCommandOptionType.String,
autocomplete: true,
required: true,
},
],
};
export async function run({ interaction }) {
if (!interaction.inCachedGuild())
return;
useMainPlayer().on('error', async (error) => {
console.error('An error occurred within the player:', error);
return;
});
const player = useMainPlayer();
const channel = interaction.member.voice.channel;
const query = interaction.options.getString('query', true);
await interaction.deferReply({ ephemeral: true });
try {
const result = await player.search(query, {
requestedBy: interaction.user,
});
if (result.hasPlaylist() && result.playlist.tracks.length > 100) {
const embed = EmbedGenerator.Error({
title: '',
description: '❌ The playlist has more than 100 tracks, which exceeds the limit.',
});
return interaction.editReply({ embeds: });
}
if (!result.hasTracks()) {
const embed = EmbedGenerator.Error({
title: '',
description: `❌ No results found for `${query}`.`,
footer: {
text: '(ℹ️) Double check the URL/Query',
}
});
return interaction.followUp({ embeds: });
}
const MAX_TIME = 2 * 60 * 60 * 1000;
const longTracks = result.tracks.filter(track => track.durationMS > MAX_TIME);
if (longTracks.length > 0) {
const embed = EmbedGenerator.Error({
title: '',
description: '❌ One or more tracks exceed the 2-hour limit.',
fields: longTracks.map(track => ({
name: track.title,
value: `Duration: ${(track.durationMS / (60 * 1000)).toFixed(2)} minutes`,
})),
footer: {
text: '(ℹ️) Ensure that the track is shorter than 2 hours.',
}
});
return interaction.editReply({ embeds: });
}
const playerOptions = await fetchPlayerOptions(interaction.guildId);
const { track, searchResult } = await player.play(channel, result, {
nodeOptions: {
metadata: PlayerMetadata.create(interaction),
volume: playerOptions.volume,
repeatMode: QueueRepeatMode[playerOptions.loopMode],
a_filter: playerOptions.filters,
equalizer: playerOptions.equalizer.map((eq, i) => ({
band: i,
gain: eq,
})),
noEmitInsert: true,
leaveOnStop: true,
leaveOnEmpty: true,
leaveOnEmptyCooldown: 5000,
leaveOnEnd: true,
leaveOnEndCooldown: 60000,
pauseOnEmpty: true,
preferBridgedMetadata: true,
disableBiquad: true,
},
requestedBy: interaction.user,
connectionOptions: {
deaf: true,
},
});
const embed = EmbedGenerator.Info({
title: `${searchResult.hasPlaylist() ? 'Playlist' : 'Track'} Queued!`,
thumbnail: { url: track.thumbnail },
description: `[${track.title} by ${track.author}](${track.url})`,
fields: searchResult.playlist
? [{ name: 'Playlist', value: searchResult.playlist.title }]
: [],
footer: {
text: 'Powered by Novonode.',
iconURL: 'https://cdn.discordapp.com/avatars/911577673292210197/620156df19613565c1e71a39c4f71691.png',
}
});
return interaction.followUp({ embeds: });
}
catch (e) {
console.error(e);
const embed = EmbedGenerator.Error({
title: '',
description: `❌ Something went wrong whilst playing `${query}`.`,
footer: {
text: '(ℹ️) Contact me on Discord IMMEDIATELY: jonno_aus',
}
});
return interaction.followUp({ embeds: });
}
}
Expected result: Awaiting the player to finish the full track first.
New contributor
Jonno is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.