maybe this fixes the audio message deleting?

This commit is contained in:
Essem 2021-07-06 08:25:12 -05:00
parent a91720c598
commit 11a77df700
No known key found for this signature in database
GPG key ID: 7D497397CC3A2A8C

View file

@ -90,11 +90,15 @@ exports.play = async (client, sound, message, music = false) => {
} }
}; };
exports.nextSong = async (client, message, connection, track, info, music, voiceChannel, loop = false, inQueue = false, lastTrack = null, oldPlaying = null) => { exports.nextSong = async (client, message, connection, track, info, music, voiceChannel, loop = false, inQueue = false, lastTrack = null) => {
const parts = Math.floor((0 / info.length) * 10); const parts = Math.floor((0 / info.length) * 10);
let playingMessage; let playingMessage;
if (!music && this.players.get(voiceChannel.guild.id)) {
const playMessage = this.players.get(voiceChannel.guild.id).playMessage;
if (playMessage.channel.messages.get(playMessage.id)) playMessage.delete();
}
if (lastTrack === track) { if (lastTrack === track) {
playingMessage = oldPlaying; playingMessage = this.players.get(voiceChannel.guild.id).playMessage;
} else { } else {
playingMessage = await client.createMessage(message.channel.id, !music ? "🔊 Playing sound..." : { playingMessage = await client.createMessage(message.channel.id, !music ? "🔊 Playing sound..." : {
"embed": { "embed": {
@ -123,10 +127,12 @@ exports.nextSong = async (client, message, connection, track, info, music, voice
}); });
} }
await connection.play(track); await connection.play(track);
this.players.set(voiceChannel.guild.id, { player: connection, type: music ? "music" : "sound", host: message.author.id, voiceChannel: voiceChannel, originalChannel: message.channel, loop: loop }); this.players.set(voiceChannel.guild.id, { player: connection, type: music ? "music" : "sound", host: message.author.id, voiceChannel: voiceChannel, originalChannel: message.channel, loop: loop, playMessage: playingMessage });
if (inQueue && connection.listeners("error").length === 0) { if (inQueue && connection.listeners("error").length === 0) {
connection.on("error", (error) => { connection.on("error", (error) => {
if (playingMessage.channel.messages.get(playingMessage.id)) playingMessage.delete(); if (playingMessage.channel.messages.get(playingMessage.id)) playingMessage.delete();
const playMessage = this.players.get(voiceChannel.guild.id).playMessage;
if (playMessage.channel.messages.get(playMessage.id)) playMessage.delete();
this.manager.leave(voiceChannel.guild.id); this.manager.leave(voiceChannel.guild.id);
connection.destroy(); connection.destroy();
this.players.delete(voiceChannel.guild.id); this.players.delete(voiceChannel.guild.id);
@ -136,11 +142,11 @@ exports.nextSong = async (client, message, connection, track, info, music, voice
} }
if (connection.listeners("end").length === 0) { if (connection.listeners("end").length === 0) {
connection.on("end", async (data) => { connection.on("end", async (data) => {
const player = this.players.get(voiceChannel.guild.id);
if (data.reason === "REPLACED") return; if (data.reason === "REPLACED") return;
const queue = this.queues.get(voiceChannel.guild.id); const queue = this.queues.get(voiceChannel.guild.id);
const isLooping = this.players.get(voiceChannel.guild.id).loop;
let newQueue; let newQueue;
if (isLooping) { if (player.loop) {
queue.push(queue.shift()); queue.push(queue.shift());
newQueue = queue; newQueue = queue;
} else { } else {
@ -154,10 +160,12 @@ exports.nextSong = async (client, message, connection, track, info, music, voice
this.queues.delete(voiceChannel.guild.id); this.queues.delete(voiceChannel.guild.id);
if (music) await client.createMessage(message.channel.id, "🔊 The current voice channel session has ended."); if (music) await client.createMessage(message.channel.id, "🔊 The current voice channel session has ended.");
if (playingMessage.channel.messages.get(playingMessage.id)) await playingMessage.delete(); if (playingMessage.channel.messages.get(playingMessage.id)) await playingMessage.delete();
if (player.playMessage.channel.messages.get(player.playMessage.id)) await player.playMessage.delete();
} else { } else {
const newTrack = await fetch(`http://${connection.node.host}:${connection.node.port}/decodetrack?track=${encodeURIComponent(newQueue[0])}`, { headers: { Authorization: connection.node.password } }).then(res => res.json()); const newTrack = await fetch(`http://${connection.node.host}:${connection.node.port}/decodetrack?track=${encodeURIComponent(newQueue[0])}`, { headers: { Authorization: connection.node.password } }).then(res => res.json());
this.nextSong(client, message, connection, newQueue[0], newTrack, music, voiceChannel, isLooping, true, track, playingMessage); this.nextSong(client, message, connection, newQueue[0], newTrack, music, voiceChannel, player.loop, true, track);
if (newQueue[0] !== track && playingMessage.channel.messages.get(playingMessage.id)) await playingMessage.delete(); if (newQueue[0] !== track && playingMessage.channel.messages.get(playingMessage.id)) await playingMessage.delete();
if (newQueue[0] !== track && player.playMessage.channel.messages.get(player.playMessage.id)) await player.playMessage.delete();
} }
}); });
} }