🐛 fix: Music skip and loop messages

This commit is contained in:
2024-08-18 16:44:12 +07:00
parent cf1b2f8f23
commit 6518681a35
4 changed files with 14 additions and 49 deletions
+4 -4
View File
@@ -224,7 +224,7 @@ export async function joinVoiceChannelProcedure(
if (!instance) return;
let previousTrack: ValidTracks | undefined;
let previousTrack: AudioInformation | null;
let isLoopMessageSent = false;
// Register Event Listeners
@@ -233,10 +233,10 @@ export async function joinVoiceChannelProcedure(
if (!current) return;
const locale = await Locale.getGuildLocale(guild.id);
previousTrack = event.instance.getPreviousTrack();
previousTrack = event.instance.nekoPlayer.getPreviousAudioInformation();
//if (current !== previousTrack) isLoopMessageSent = false;
//else if (current === previousTrack && isLoopMessageSent) return;
if (current !== previousTrack) isLoopMessageSent = false;
else if (current === previousTrack && isLoopMessageSent) return;
const row = new ActionRowBuilder<ButtonBuilder>();
// if (event.instance.queue.track[0] instanceof SpotifyTrack)
+1 -1
View File
@@ -86,7 +86,7 @@ export default class Skip extends DiscordModule {
embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)]
});
instance.skipTrack();
instance.skip();
if (!instance.nekoPlayer.getCurrentAudioInformation())
return await sendHybridInteractionMessageResponse(data, {
+8 -43
View File
@@ -189,7 +189,7 @@ export class DiscordMusicPlayerInstance {
public textChannel?: BaseGuildTextChannel | BaseGuildVoiceChannel;
public voiceChannel: VoiceChannel | StageChannel;
public voiceConnection?: VoiceConnection;
public previousTrack?: ValidTracks;
public previousTrack?: AudioInformation;
public paused: boolean = false;
@@ -209,38 +209,6 @@ export class DiscordMusicPlayerInstance {
this.voiceChannel = voiceChannel;
this.events = new EventEmitter();
// this.player.on(AudioPlayerStatus.Idle, async (oldStage, newStage) => {
// //The player stopped
// if (newStage.status === AudioPlayerStatus.Idle && oldStage.status !== AudioPlayerStatus.Idle) {
// // Loop mode is set to current song
// if (this.loopMode === DiscordMusicPlayerLoopMode.Current) {
// if (this.queue.track.length !== 0) {
// this.previousTrack = this.queue.track[0];
// this.playTrack(this.queue.track[0]);
// }
// return;
// }
// // There are more songs in the queue, remove finished song and play the next one
// if (this.queue.track.length !== 0) {
// let previousTrack = this.queue.track.shift();
// if (previousTrack) this.previousTrack = previousTrack;
// if (this.queue.track.length > 0) {
// this.playTrack(this.queue.track[0]);
// }
// }
// }
// });
// this.player.on(AudioPlayerStatus.Playing, (oldState: any, newState: any) => {
// this.events.emit('playing', new PlayerPlayingEvent(this));
// });
// this.player.on('error', (error: Error) => {
// this.events.emit('error', new PlayerErrorEvent(this, error));
// });
this.nekoPlayer.on('play', (information: AudioInformation) => {
if (!this.nekoPlayer.stream) throw new Error('No input stream');
@@ -329,17 +297,14 @@ export class DiscordMusicPlayerInstance {
this.paused = false;
}
public async addTrackToQueue(track: ValidTracks) {
return await this.nekoPlayer.enqueue(track.url);
public async skip() {
if (!this.voiceConnection) throw new Error('No voice connection');
this.discordPlayer.pause(true);
this.nekoPlayer.skip();
}
public async skipTrack() {
if (!this.voiceConnection) throw new Error('No voice connection');
if (this.nekoPlayer.getQueue().length === 0) return;
await this.nekoPlayer.skip();
if (this.paused) this.paused = false;
public async addTrackToQueue(track: ValidTracks) {
return await this.nekoPlayer.enqueue(track.url);
}
public clearQueue() {
@@ -367,7 +332,7 @@ export class DiscordMusicPlayerInstance {
this.queue.track = shuffleFixedFirst(this.queue.track);
}
public getPreviousTrack(): ValidTracks | undefined {
public getPreviousTrack(): AudioInformation | undefined {
return this.previousTrack;
}