Add config option to make the bot stay in voice chat
This commit is contained in:
parent
5d89d78b44
commit
14046a811a
3 changed files with 23 additions and 13 deletions
|
@ -24,10 +24,9 @@ PREFIX=&
|
|||
# Optional
|
||||
###########
|
||||
|
||||
# Put the default emoji for processing messages here, more can be specified in messages.json
|
||||
# Example:
|
||||
# PROCESSING_EMOJI=<a:processing:818243325891051581>
|
||||
PROCESSING_EMOJI=
|
||||
# Set this to true if you want the bot to stay in voice chats after sound effects and music have stopped
|
||||
# (you can still make the bot leave using the stop command)
|
||||
STAYVC=false
|
||||
|
||||
# Put Mashape/RapidAPI key here
|
||||
MASHAPE=
|
||||
|
|
|
@ -5,7 +5,7 @@ import { random } from "../utils/misc.js";
|
|||
export default async (client, cluster, worker, ipc, member, oldChannel) => {
|
||||
if (!oldChannel) return;
|
||||
const connection = players.get(oldChannel.guild.id);
|
||||
if (connection && connection.type === "music" && oldChannel.id === connection.voiceChannel.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);
|
||||
const waitMessage = await client.createMessage(connection.originalChannel.id, "🔊 Waiting 10 seconds for someone to return...");
|
||||
|
@ -72,4 +72,4 @@ export default async (client, cluster, worker, ipc, member, oldChannel) => {
|
|||
await client.createMessage(connection.originalChannel.id, "🔊 The current voice channel session has ended.");
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
|
|
@ -77,7 +77,7 @@ export async function play(client, sound, message, music = false) {
|
|||
node: node.id
|
||||
});
|
||||
|
||||
if (oldQueue && music) {
|
||||
if (oldQueue && oldQueue.length !== 0 && music) {
|
||||
return `Your ${playlistInfo.name ? "playlist" : "tune"} \`${playlistInfo.name ? playlistInfo.name : (tracks[0].info.title !== "" ? tracks[0].info.title : "(blank)")}\` has been added to the queue!`;
|
||||
} else {
|
||||
nextSong(client, message, connection, tracks[0].track, tracks[0].info, music, voiceChannel, player ? player.loop : false, player ? player.shuffle : false);
|
||||
|
@ -151,6 +151,10 @@ export async function nextSong(client, message, connection, track, info, music,
|
|||
if (data.reason === "REPLACED") return;
|
||||
let queue = queues.get(voiceChannel.guild.id);
|
||||
const player = players.get(voiceChannel.guild.id);
|
||||
if (player && process.env.STAYVC === "true") {
|
||||
player.type = "idle";
|
||||
players.set(voiceChannel.guild.id, player);
|
||||
}
|
||||
let newQueue;
|
||||
if (player && player.shuffle) {
|
||||
if (player.loop) {
|
||||
|
@ -167,7 +171,16 @@ export async function nextSong(client, message, connection, track, info, music,
|
|||
newQueue = queue ? queue.slice(1) : [];
|
||||
}
|
||||
queues.set(voiceChannel.guild.id, newQueue);
|
||||
if (newQueue.length === 0) {
|
||||
if (newQueue.length !== 0) {
|
||||
const newTrack = await Rest.decode(connection.node, newQueue[0]);
|
||||
nextSong(client, message, connection, newQueue[0], newTrack, music, voiceChannel, player.loop, player.shuffle, track);
|
||||
try {
|
||||
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();
|
||||
} catch {
|
||||
// no-op
|
||||
}
|
||||
} else if (process.env.STAYVC !== "true") {
|
||||
manager.leave(voiceChannel.guild.id);
|
||||
connection.destroy();
|
||||
players.delete(voiceChannel.guild.id);
|
||||
|
@ -181,14 +194,12 @@ export async function nextSong(client, message, connection, track, info, music,
|
|||
// no-op
|
||||
}
|
||||
} else {
|
||||
const newTrack = await Rest.decode(connection.node, newQueue[0]);
|
||||
nextSong(client, message, connection, newQueue[0], newTrack, music, voiceChannel, player.loop, player.shuffle, track);
|
||||
try {
|
||||
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();
|
||||
if (playingMessage.channel.messages.get(playingMessage.id)) await playingMessage.delete();
|
||||
if (player && player.playMessage.channel.messages.get(player.playMessage.id)) await player.playMessage.delete();
|
||||
} catch {
|
||||
// no-op
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue