Add stop functionality, fix duration
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
30
commands/stop.js
Normal 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;
|
||||
Reference in New Issue
Block a user