Properly await more functions

This commit is contained in:
Essem 2021-12-13 16:09:12 -06:00
parent c5fc1d0b0f
commit 5acd2b1113
No known key found for this signature in database
GPG Key ID: 7D497397CC3A2A8C
7 changed files with 26 additions and 26 deletions

View File

@ -7,7 +7,7 @@ class PauseCommand extends MusicCommand {
if (!this.message.channel.guild.members.get(this.client.user.id).voiceState.channelID) return "I'm not in a voice channel!";
if (this.connection.host !== this.message.author.id && !this.message.member.permissions.has("manageChannels")) return "Only the current voice session host can pause/resume the music!";
const player = this.connection.player;
player.pause(!player.paused ? true : false);
await player.pause(!player.paused ? true : false);
return `🔊 The player has been ${!player.paused ? "paused" : "resumed"}.`;
}
@ -15,4 +15,4 @@ class PauseCommand extends MusicCommand {
static aliases = ["resume"];
}
export default PauseCommand;
export default PauseCommand;

View File

@ -20,4 +20,4 @@ class RemoveCommand extends MusicCommand {
static aliases = ["rm"];
}
export default RemoveCommand;
export default RemoveCommand;

View File

@ -12,7 +12,7 @@ class SeekCommand extends MusicCommand {
if (!track.isSeekable) return "This track isn't seekable!";
const seconds = parseFloat(this.args[0]);
if (isNaN(seconds) || (seconds * 1000) > track.length || (seconds * 1000) < 0) return "That's not a valid position!";
player.seek(seconds * 1000);
await player.seek(seconds * 1000);
return `🔊 Seeked track to ${seconds} second(s).`;
}
@ -21,4 +21,4 @@ class SeekCommand extends MusicCommand {
static arguments = ["[seconds]"];
}
export default SeekCommand;
export default SeekCommand;

View File

@ -16,14 +16,14 @@ class SkipCommand extends MusicCommand {
max: votes.max
};
if (votes.count + 1 === votes.max) {
player.player.stop(this.message.channel.guild.id);
await player.player.stop(this.message.channel.guild.id);
skipVotes.set(this.message.channel.guild.id, { count: 0, ids: [], max: Math.min(3, player.voiceChannel.voiceMembers.filter((i) => i.id !== this.client.user.id && !i.bot).length) });
} else {
skipVotes.set(this.message.channel.guild.id, newObject);
return `🔊 Voted to skip song (${votes.count + 1}/${votes.max} people have voted).`;
}
} else {
player.player.stop(this.message.channel.guild.id);
await player.player.stop(this.message.channel.guild.id);
return;
}
}
@ -32,4 +32,4 @@ class SkipCommand extends MusicCommand {
static aliases = ["forceskip"];
}
export default SkipCommand;
export default SkipCommand;

View File

@ -7,9 +7,9 @@ class StopCommand extends MusicCommand {
if (!this.message.member.voiceState.channelID) return "You need to be in a voice channel first!";
if (!this.message.channel.guild.members.get(this.client.user.id).voiceState.channelID) return "I'm not in a voice channel!";
if (this.connection.host !== this.message.author.id && !this.message.member.permissions.has("manageChannels")) return "Only the current voice session host can stop the music!";
manager.leave(this.message.channel.guild.id);
await manager.leave(this.message.channel.guild.id);
const connection = this.connection.player;
connection.destroy();
await connection.destroy();
players.delete(this.message.channel.guild.id);
queues.delete(this.message.channel.guild.id);
return "🔊 The current voice channel session has ended.";
@ -19,4 +19,4 @@ class StopCommand extends MusicCommand {
static aliases = ["disconnect"];
}
export default StopCommand;
export default StopCommand;

View File

@ -7,12 +7,12 @@ export default async (client, cluster, worker, ipc, member, oldChannel) => {
const connection = players.get(oldChannel.guild.id);
if (connection && oldChannel.id === connection.voiceChannel.id) {
if (oldChannel.voiceMembers.filter((i) => i.id !== client.user.id && !i.bot).length === 0) {
connection.player.pause(true);
await connection.player.pause(true);
const waitMessage = await client.createMessage(connection.originalChannel.id, "🔊 Waiting 10 seconds for someone to return...");
const awaitRejoin = new AwaitRejoin(oldChannel, true);
awaitRejoin.on("end", async (rejoined, member) => {
if (rejoined) {
connection.player.pause(false);
await connection.player.pause(false);
players.set(connection.voiceChannel.guild.id, { player: connection.player, type: connection.type, host: member.id, voiceChannel: connection.voiceChannel, originalChannel: connection.originalChannel, loop: connection.loop, shuffle: connection.shuffle, playMessage: connection.playMessage });
waitMessage.edit(`🔊 ${member.mention} is the new voice channel host.`);
} else {
@ -21,9 +21,9 @@ export default async (client, cluster, worker, ipc, member, oldChannel) => {
} catch {
// no-op
}
connection.player.stop(connection.originalChannel.guild.id);
manager.leave(connection.originalChannel.guild.id);
connection.player.destroy();
await connection.player.stop(connection.originalChannel.guild.id);
await manager.leave(connection.originalChannel.guild.id);
await connection.player.destroy();
players.delete(connection.originalChannel.guild.id);
queues.delete(connection.originalChannel.guild.id);
skipVotes.delete(connection.originalChannel.guild.id);
@ -48,9 +48,9 @@ export default async (client, cluster, worker, ipc, member, oldChannel) => {
} catch {
// no-op
}
connection.player.stop(connection.originalChannel.guild.id);
manager.leave(connection.originalChannel.guild.id);
connection.player.destroy();
await connection.player.stop(connection.originalChannel.guild.id);
await manager.leave(connection.originalChannel.guild.id);
await connection.player.destroy();
players.delete(connection.originalChannel.guild.id);
queues.delete(connection.originalChannel.guild.id);
skipVotes.delete(connection.originalChannel.guild.id);
@ -63,9 +63,9 @@ export default async (client, cluster, worker, ipc, member, oldChannel) => {
}
});
} else if (member.id === client.user.id) {
connection.player.stop(connection.originalChannel.guild.id);
manager.leave(connection.originalChannel.guild.id);
connection.player.destroy();
await connection.player.stop(connection.originalChannel.guild.id);
await manager.leave(connection.originalChannel.guild.id);
await connection.player.destroy();
players.delete(connection.originalChannel.guild.id);
queues.delete(connection.originalChannel.guild.id);
skipVotes.delete(connection.originalChannel.guild.id);

View File

@ -140,9 +140,9 @@ export async function nextSong(client, message, connection, track, info, music,
} catch {
// no-op
}
manager.leave(voiceChannel.guild.id);
await manager.leave(voiceChannel.guild.id);
connection.removeAllListeners("end");
connection.destroy();
await connection.destroy();
players.delete(voiceChannel.guild.id);
queues.delete(voiceChannel.guild.id);
logger.error(error);
@ -181,8 +181,8 @@ export async function nextSong(client, message, connection, track, info, music,
// no-op
}
} else if (process.env.STAYVC !== "true") {
manager.leave(voiceChannel.guild.id);
connection.destroy();
await manager.leave(voiceChannel.guild.id);
await connection.destroy();
players.delete(voiceChannel.guild.id);
queues.delete(voiceChannel.guild.id);
skipVotes.delete(voiceChannel.guild.id);