Add stop functionality, fix duration

This commit is contained in:
Azaaxin
2023-06-25 11:08:14 +02:00
committed by Myx
parent dddbe81fab
commit c802be1a61
17 changed files with 304 additions and 226 deletions

View File

@@ -1,32 +1,34 @@
const musicQueue = require('../musicQueue');
const musicQueue = require("../musicQueue");
async function enableLooping(interaction) {
await interaction.deferReply();
const guildId = interaction.guild.id;
musicQueue.enableLooping(guildId);
interaction.followUp('Enabled looping for the current queue.');
interaction.followUp("Enabled looping for the current queue.");
}
async function unloopCommand(interaction) {
await interaction.deferReply();
const guildId = interaction.guild.id;
musicQueue.disableLooping(guildId);
interaction.followUp('Disabled looping for the current queue.');
interaction.followUp("Disabled looping for the current queue.");
}
async function toggleLoopCommand(interaction) {
await interaction.deferReply();
const guildId = interaction.guild.id;
if (musicQueue.looping.has(guildId) && musicQueue.looping.get(guildId)) {
musicQueue.disableLooping(guildId, false);
interaction.followUp('Disabled looping for the current queue.');
} else {
musicQueue.enableLooping(guildId, true);
interaction.followUp('Enabled looping for the current queue.');
}
await interaction.deferReply();
const guildId = interaction.guild.id;
if (musicQueue.looping.has(guildId) && musicQueue.looping.get(guildId)) {
musicQueue.disableLooping(guildId, false);
interaction.followUp("Disabled looping for the current queue.");
} else {
musicQueue.enableLooping(guildId, true);
interaction.followUp("Enabled looping for the current queue.");
}
}
module.exports.toggleLoopCommand = toggleLoopCommand;
module.exports.unloopCommand = unloopCommand;
module.exports.enableLooping = enableLooping;
module.exports.enableLooping = enableLooping;

View File

@@ -1,32 +0,0 @@
const { musicPlayer } = require('../utils/musicPlayer');
const { AudioPlayerStatus, joinVoiceChannel, AudioPlayerState } = require('@discordjs/voice');
async function pauseCommand(interaction) {
await interaction.deferReply();
const voiceChannel = interaction.member.voice.channel;
const connection = joinVoiceChannel({
channelId: voiceChannel.id,
guildId: interaction.guild.id,
adapterCreator: interaction.guild.voiceAdapterCreator,
selfDeaf: false,
selfMute: false
});
let player = await musicPlayer(interaction.guild.id, connection, false);
if (!voiceChannel) {
return interaction.followUp('You must be in a voice channel to use this command.');
}
if (!player) {
return interaction.followUp('I am not currently playing music in a voice channel.');
}
// player.pause();
interaction.followUp('Paused the music.');
}
module.exports.pauseCommand = pauseCommand;

View File

@@ -1,24 +1,34 @@
const { getVoiceConnection } = require('@discordjs/voice');
const { getVoiceConnection } = require("@discordjs/voice");
async function pauseCommand(interaction) {
await interaction.deferReply();
const connection = getVoiceConnection(interaction.guild.id);
if (!connection) {
return interaction.followUp('There is no active music player in this server.');
return interaction.followUp(
"There is no active music player in this server."
);
}
connection.state.subscription.player.pause();
interaction.followUp('Paused the music.');
interaction.followUp("Paused the music.");
}
async function unpauseCommand(interaction) {
await interaction.deferReply();
const connection = getVoiceConnection(interaction.guild.id);
if (!connection) {
return interaction.followUp('There is no active music player in this server.');
return interaction.followUp(
"There is no active music player in this server."
);
}
connection.state.subscription.player.unpause();
interaction.followUp('Unpaused the music.');
interaction.followUp("Resumed the music.");
}
module.exports.pauseCommand = pauseCommand;
module.exports.unpauseCommand = unpauseCommand;
module.exports.unpauseCommand = unpauseCommand;

View File

@@ -1,33 +1,32 @@
const { getMusicStream } = require('./../utils/getMusicStream');
const musicQueue = require('../musicQueue');
const { musicPlayer } = require('../utils/musicPlayer');
const {
joinVoiceChannel,
} = require('@discordjs/voice');
const { getMusicStream } = require("./../utils/getMusicStream");
const musicQueue = require("../musicQueue");
const { musicPlayer } = require("../utils/musicPlayer");
const { joinVoiceChannel } = require("@discordjs/voice");
async function playCommand(interaction) {
await interaction.deferReply();
const query = interaction.options.getString('input');
const voiceChannel = interaction.member.voice.channel;
if (!voiceChannel) {
return interaction.followUp('You must be in a voice channel to use this command.');
}
const song = await getMusicStream(query);
musicQueue.addToQueue(interaction.guild.id, song);
const connection = joinVoiceChannel({
channelId: voiceChannel.id,
guildId: interaction.guild.id,
adapterCreator: interaction.guild.voiceAdapterCreator,
selfDeaf: false,
selfMute: false
});
musicPlayer(interaction.guild.id, connection, interaction);
await interaction.deferReply();
const query = interaction.options.getString("input");
const voiceChannel = interaction.member.voice.channel;
if (!voiceChannel) {
return interaction.followUp(
"You must be in a voice channel to use this command."
);
}
const song = await getMusicStream(query);
musicQueue.addToQueue(interaction.guild.id, song);
const connection = joinVoiceChannel({
channelId: voiceChannel.id,
guildId: interaction.guild.id,
adapterCreator: interaction.guild.voiceAdapterCreator,
selfDeaf: false,
selfMute: false,
});
musicPlayer(interaction.guild.id, connection, interaction);
}
module.exports.playCommand = playCommand;
module.exports.playCommand = playCommand;

View File

@@ -1,24 +1,27 @@
const musicQueue = require('../musicQueue');
const { getMusicStream } = require('../utils/getMusicStream');
const musicQueue = require("../musicQueue");
const { getMusicStream } = require("../utils/getMusicStream");
async function queueCommand(interaction) {
await interaction.deferReply();
await interaction.deferReply();
const query = interaction.options.getString('song');
const voiceChannel = interaction.member.voice.channel;
const query = interaction.options.getString("song");
const voiceChannel = interaction.member.voice.channel;
if (!voiceChannel) {
return interaction.followUp('You must be in a voice channel to use this command.');
}
if (!voiceChannel) {
return interaction.followUp(
"You must be in a voice channel to use this command."
);
}
const song = await getMusicStream(query);
if (!song) {
return interaction.followUp('Error finding song. Try Again.').then(msg => setTimeout(() => msg.delete(), 10000));
}
const song = await getMusicStream(query);
if (!song) {
return interaction
.followUp("Error finding song. Try Again.")
.then((msg) => setTimeout(() => msg.delete(), 10000));
}
musicQueue.addToQueue(interaction.guild.id, song);
interaction.followUp(`Added ${song.title} to the queue.`);
musicQueue.addToQueue(interaction.guild.id, song);
interaction.followUp(`Added ${song.title} to the queue.`);
}
module.exports.queueCommand = queueCommand;

View File

@@ -1,32 +0,0 @@
const { musicPlayer } = require('../utils/musicPlayer');
const { joinVoiceChannel } = require('@discordjs/voice');
async function resumeCommand(interaction) {
await interaction.deferReply();
const voiceChannel = interaction.member.voice.channel;
const connection = joinVoiceChannel({
channelId: voiceChannel.id,
guildId: interaction.guild.id,
adapterCreator: interaction.guild.voiceAdapterCreator,
selfDeaf: false,
selfMute: false
});
let player = await musicPlayer(interaction.guild.id, connection, false);
if (!voiceChannel) {
return interaction.followUp('You must be in a voice channel to use this command.');
}
if (!player) {
return interaction.followUp('I am not currently playing music in a voice channel.');
}
player.unpause();
interaction.followUp('Resumed the music.');
}
module.exports.resumeCommand = resumeCommand;

30
commands/stop.js Normal file
View File

@@ -0,0 +1,30 @@
const musicQueue = require("../musicQueue");
const { getVoiceConnection } = require("@discordjs/voice");
async function stopCommand(interaction) {
await interaction.deferReply();
const voiceChannel = interaction.member.voice.channel;
const connection = getVoiceConnection(interaction.guild.id);
if (!voiceChannel) {
return interaction.followUp(
"You must be in a voice channel to use this command."
);
}
const guildId = interaction.guild.id;
if (!connection.state.subscription.player) {
return interaction.followUp(
"I am not currently playing music in a voice channel."
);
}
connection.state.subscription.player.stop();
musicQueue.clearQueue(guildId);
interaction.followUp("Stopped the music and cleared the queue.");
}
module.exports.stopCommand = stopCommand;