Add more commands
This commit is contained in:
30
commands/leave.js
Normal file
30
commands/leave.js
Normal file
@@ -0,0 +1,30 @@
|
||||
// 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;
|
||||
@@ -27,10 +27,11 @@ async function playCommand(interaction) {
|
||||
|
||||
if (musicQueue.getQueue(interaction.guild.id).length > 0) {
|
||||
musicQueue.removeFromQueue(interaction.guild.id);
|
||||
musicQueue.addToQueue(interaction.guild.id, song, true);
|
||||
} else {
|
||||
musicQueue.addToQueue(interaction.guild.id, song);
|
||||
}
|
||||
|
||||
musicQueue.addToQueue(interaction.guild.id, song);
|
||||
|
||||
musicPlayer(
|
||||
interaction.guild.id,
|
||||
connection,
|
||||
|
||||
39
commands/previous.js
Normal file
39
commands/previous.js
Normal file
@@ -0,0 +1,39 @@
|
||||
const { joinVoiceChannel } = require('@discordjs/voice');
|
||||
const musicQueue = require('../musicQueue');
|
||||
const { musicPlayer } = require('../utils/musicPlayer');
|
||||
|
||||
function previousCommand(interaction) {
|
||||
// Get the server queue
|
||||
const serverQueue = musicQueue.getQueue(interaction.guild.id);
|
||||
|
||||
const voiceChannel = interaction.member.voice.channel;
|
||||
|
||||
if (!voiceChannel) {
|
||||
return interaction.followUp(
|
||||
'You must be in a voice channel to use this command.',
|
||||
);
|
||||
}
|
||||
|
||||
const connection = joinVoiceChannel({
|
||||
channelId: voiceChannel.id,
|
||||
guildId: interaction.guild.id,
|
||||
adapterCreator: interaction.guild.voiceAdapterCreator,
|
||||
selfDeaf: false,
|
||||
selfMute: false,
|
||||
});
|
||||
|
||||
// Check if there is a previous song in the queue
|
||||
if (serverQueue.previous === undefined) {
|
||||
return interaction.reply('There is no previous song to go back to!');
|
||||
}
|
||||
|
||||
// Add the previous song back to the front of the queue
|
||||
musicQueue.addToQueue(interaction.guild.id, serverQueue.previous, true);
|
||||
|
||||
// Play the previous song
|
||||
musicPlayer(interaction.guild.id, connection, interaction);
|
||||
|
||||
return interaction.reply('Went back to the previous song!');
|
||||
}
|
||||
|
||||
module.exports.previousCommand = previousCommand;
|
||||
40
commands/skip.js
Normal file
40
commands/skip.js
Normal file
@@ -0,0 +1,40 @@
|
||||
const { joinVoiceChannel } = require('@discordjs/voice');
|
||||
const musicQueue = require('../musicQueue');
|
||||
const { musicPlayer } = require('../utils/musicPlayer');
|
||||
|
||||
async function skipCommand(interaction) {
|
||||
// Get the server queue
|
||||
interaction.deferReply();
|
||||
const serverQueue = musicQueue.getQueue(interaction.guild.id);
|
||||
|
||||
const voiceChannel = interaction.member.voice.channel;
|
||||
|
||||
if (!voiceChannel) {
|
||||
return interaction.followUp(
|
||||
'You must be in a voice channel to use this command.',
|
||||
);
|
||||
}
|
||||
|
||||
const connection = joinVoiceChannel({
|
||||
channelId: voiceChannel.id,
|
||||
guildId: interaction.guild.id,
|
||||
adapterCreator: interaction.guild.voiceAdapterCreator,
|
||||
selfDeaf: false,
|
||||
selfMute: false,
|
||||
});
|
||||
|
||||
// Check if there are any songs in the queue
|
||||
if (serverQueue.length === 0) {
|
||||
return interaction.reply('There are no songs in the queue to skip!');
|
||||
}
|
||||
|
||||
// Remove the current song from the queue
|
||||
musicQueue.removeFromQueue(interaction.guild.id);
|
||||
|
||||
// Play the next song
|
||||
await musicPlayer(interaction.guild.id, connection, interaction);
|
||||
|
||||
return interaction.reply('Skipped to the next song!');
|
||||
}
|
||||
|
||||
module.exports.skipCommand = skipCommand;
|
||||
Reference in New Issue
Block a user