This repository has been archived on 2026-01-13. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Lunaris/commands/leave.js
2023-07-02 01:57:55 +02:00

30 lines
966 B
JavaScript

// leaveCommand.js
const { getVoiceConnection } = require('@discordjs/voice');
const { intervalMap } = require('../utils/nowPlayingMessage'); // Import the intervalMap from the nowPlayingMessage module
const ConsolerLogger = require('../utils/logger');
const logger = new ConsolerLogger();
async function leaveCommand(interaction) {
await interaction.deferReply();
try {
const guildId = interaction.guild.id;
const connection = getVoiceConnection(guildId);
if (!connection) {
return interaction.followUp('I am not currently in a voice channel.');
}
// Clear the interval for updating the progress bar
const interval = intervalMap.get(guildId);
clearInterval(interval);
connection.destroy();
return interaction.followUp('I have left the voice channel.');
} catch (error) {
logger.error(error);
return interaction.followUp('An error occurred while trying to leave the voice channel.');
}
}
module.exports.leaveCommand = leaveCommand;