@getsolara/solara.voice
Version:
Optional voice functionality for @getsolara/solara.js using @discordjs/voice
33 lines • 1.63 kB
JavaScript
module.exports = {
name: "$voiceLeave",
description: "Makes the bot leave its current voice channel in the guild.",
takesBrackets: false,
execute: async (context, args) => {
if (context.client.voiceInitialized === false) {
return "[Error: $voiceLeave requires voice features to be enabled. Ensure @getsolara/solara.voice is installed and configured correctly.]";
}
if (!context.guild) return "[Error: $voiceLeave can only be used in a server.]";
const connection = context.client.solaraVoiceConnections?.get(context.guild.id);
if (connection) {
try {
const { VoiceConnectionStatus } = require('@discordjs/voice');
const player = context.client.solaraAudioPlayers?.get(context.guild.id);
if (player) {
player.stop(true);
}
if (connection.state.status !== VoiceConnectionStatus.Destroyed) {
connection.destroy();
}
return "Left voice channel.";
} catch (e) {
if (e.code === 'MODULE_NOT_FOUND' && e.message.includes('@discordjs/voice')) {
return "[Error: $voiceLeave - @discordjs/voice module missing internally.]";
}
console.error(`Solara.voice Error ($voiceLeave) for guild ${context.guild.id}:`, e);
return `[Error leaving voice channel: ${e.message}]`;
}
} else {
return "[Bot is not in a voice channel in this server.]";
}
}
};