Merge pull request #62 from mariusbegby/add-loop-command

Add loop command
This commit is contained in:
Marius Begby authored and GitHub committed 2023-07-16 02:36:18 +02:00
commit 591b7241d3
12 files changed
+318 -62

No files matched your search

+7 -3
View File
@@ -129,7 +129,9 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setAuthor({
name: interaction.member.nickname || interaction.user.username,
name:
interaction.member.nickname ||
interaction.user.username,
iconURL: interaction.user.avatarURL()
})
.setDescription(
@@ -148,7 +150,9 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setAuthor({
name: interaction.member.nickname || interaction.user.username,
name:
interaction.member.nickname ||
interaction.user.username,
iconURL: interaction.user.avatarURL()
})
.setDescription(
@@ -164,7 +168,7 @@ module.exports = {
).label
}\``
)
.join(', ')}`
.join(', ')}.`
)
.setColor(embedColors.colorSuccess)
],
+5 -4
View File
@@ -13,15 +13,16 @@ module.exports = {
new EmbedBuilder()
.setDescription(
`${embedIcons.rule} **List of commands**\n` +
'- `/play` `query` - Add a track or playlist to the queue by searching or url.\n' +
'- `/play` `query` - Add a track or playlist to the queue by url or search.\n' +
'- `/pause` - Pause or resume the current track.\n' +
'- `/queue` `[page]` - Show the list of tracks added to the queue.\n' +
`- \`/nowplaying\` - ${embedIcons.new} Show information about the track currently playing.\n` +
`- \`/loop\` \`mode\` - ${embedIcons.beta} Toggle looping a track, the whole queue or autoplay.\n` +
`- \`/filters\` - ${embedIcons.beta} Toggle various audio filters during playback.\n` +
'- `/volume` `[percentage]` - Show or set the playback volume for tracks.\n' +
'- `/skip` `[trackNumber]` - Skip current or specified track.\n' +
'- `/remove` `trackNumber` - Remove a specific track from the queue.\n' +
'- `/leave` - Clear the track queue and remove the bot from voice channel.\n\n' +
'- `/skip` `[trackNumber]` - Skip to next or specified track.\n' +
'- `/remove` `trackNumber` - Remove specified track from the queue.\n' +
'- `/leave` - Clear the queue and remove the bot from voice channel.\n\n' +
`${embedIcons.support} **Support server**\nJoin the support server for help or suggestions: \n**${botInfo.supportServerInviteUrl}**\n\n` +
`${embedIcons.bot} **Enjoying ${botInfo.name}?**\nAdd me to another server: \n**[Click me!](${botInfo.botInviteUrl})**`
)
+156
View File
@@ -0,0 +1,156 @@
const { SlashCommandBuilder } = require('@discordjs/builders');
const { useQueue } = require('discord-player');
const { EmbedBuilder } = require('discord.js');
const { embedColors, embedIcons, botInfo } = require('../config.json');
module.exports = {
data: new SlashCommandBuilder()
.setName('loop')
.setDescription('Toggle looping a track or the whole queue.')
.setDMPermission(false)
.addStringOption((option) =>
option
.setName('mode')
.setDescription('Track number to remove from queue.')
.setRequired(false)
.addChoices(
{ name: 'Track', value: '1' },
{ name: 'Queue', value: '2' },
{ name: 'Autoplay', value: '3' },
{ name: 'Disabled', value: '0' }
)
),
run: async ({ interaction }) => {
if (!interaction.member.voice.channel) {
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedIcons.warning} Oops!**\nYou need to be in a voice channel to use this command.`
)
.setColor(embedColors.colorWarning)
]
});
}
const queue = useQueue(interaction.guild.id);
if (!queue) {
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedIcons.warning} Oops!**\nThere are no tracks in the queue and nothing currently playing. First add some tracks with \`/play\`!`
)
.setColor(embedColors.colorWarning)
]
});
}
const loopModesFormatted = new Map([
[0, 'disabled'],
[1, 'track'],
[2, 'queue'],
[3, 'autoplay']
]);
const mode = parseInt(interaction.options.getString('mode'));
const modeUserString = loopModesFormatted.get(mode);
const currentMode = queue.repeatMode;
const currentModeUserString = loopModesFormatted.get(currentMode);
if (!mode && mode !== 0) {
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setDescription(
`**${
currentMode === 3
? embedIcons.autoplay
: embedIcons.loop
} Current loop mode**\nThe looping mode is currently set to \`${currentModeUserString}\`.`
)
.setColor(embedColors.colorInfo)
]
});
}
if (mode === currentMode) {
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedIcons.warning} Oops!**\nLoop mode is already \`${modeUserString}\`.`
)
.setColor(embedColors.colorWarning)
]
});
}
queue.setRepeatMode(mode);
if (!queue.repeatMode === mode) {
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedIcons.error} Uh-oh... Failed to change loop mode!**\nI tried to change the loop mode to \`${modeUserString}\`, but something went wrong.\n\nYou can try to perform the command again.\n\n_If you think this message is incorrect or the issue persists, please submit a bug report in the **[support server](${botInfo.supportServerInviteUrl})**._`
)
.setColor(embedColors.colorError)
]
});
}
if (queue.repeatMode === 0) {
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setAuthor({
name:
interaction.member.nickname ||
interaction.user.username,
iconURL: interaction.user.avatarURL()
})
.setDescription(
`**${embedIcons.success} Loop mode disabled**\nChanging loop mode from \`${currentModeUserString}\` to \`${modeUserString}\`.\n\nThe ${currentModeUserString} will no longer play on repeat!`
)
.setColor(embedColors.colorSuccess)
]
});
}
if (queue.repeatMode === 3) {
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setAuthor({
name:
interaction.member.nickname ||
interaction.user.username,
iconURL: interaction.user.avatarURL()
})
.setDescription(
`**${embedIcons.autoplaying} Loop mode changed**\nChanging loop mode from \`${currentModeUserString}\` to \`${modeUserString}\`.\n\nWhen the queue is empty, similar tracks will start playing!`
)
.setColor(embedColors.colorSuccess)
]
});
}
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setAuthor({
name:
interaction.member.nickname ||
interaction.user.username,
iconURL: interaction.user.avatarURL()
})
.setDescription(
`**${embedIcons.looping} Loop mode changed**\nChanging loop mode from \`${currentModeUserString}\` to \`${modeUserString}\`.\n\nThe ${modeUserString} will now play on repeat!`
)
.setColor(embedColors.colorSuccess)
]
});
}
};
+38 -6
View File
@@ -60,11 +60,13 @@ module.exports = {
]);
const currentTrack = queue.currentTrack;
let author = currentTrack.author ? currentTrack.author : 'Unavailable';
if (author === 'cdn.discordapp.com') {
author = 'Unavailable';
}
let plays = currentTrack.views !== 0 ? currentTrack.views : 0;
if (
plays === 0 &&
currentTrack.metadata.bridge &&
@@ -72,9 +74,10 @@ module.exports = {
currentTrack.metadata.bridge.views !== undefined
) {
plays = currentTrack.metadata.bridge.views;
} else {
} else if (plays === 0) {
plays = 'Unavailable';
}
const source =
sourceStringsFormatted.get(currentTrack.raw.source) ??
'Unavailable';
@@ -106,6 +109,15 @@ module.exports = {
.setEmoji(embedIcons.nextTrack)
);
const loopModesFormatted = new Map([
[0, 'disabled'],
[1, 'track'],
[2, 'queue'],
[3, 'autoplay']
]);
const loopModeUserString = loopModesFormatted.get(queue.repeatMode);
const response = await interaction.editReply({
embeds: [
new EmbedBuilder()
@@ -119,11 +131,18 @@ module.exports = {
(queue.node.isPaused()
? '**Currently Paused**\n'
: `**${embedIcons.audioPlaying} Now Playing**\n`) +
(currentTrack
? `**[${currentTrack.title}](${currentTrack.url})**`
: 'None') +
`**[${currentTrack.title}](${currentTrack.url})**` +
`\nRequested by: <@${currentTrack.requestedBy.id}>` +
`\n ${bar}\n\n`
`\n ${bar}\n\n` +
`${
queue.repeatMode === 0
? ''
: `**${
queue.repeatMode === 3
? embedIcons.autoplay
: embedIcons.loop
} Looping**\nLoop mode is set to ${loopModeUserString}. You can change it with \`/loop\`.`
}`
)
.addFields(
{
@@ -200,6 +219,10 @@ module.exports = {
: `\`${skippedTrack.duration}\``;
queue.node.skip();
const repeatModeUserString = loopModesFormatted.get(
queue.repeatMode
);
return await interaction.followUp({
embeds: [
new EmbedBuilder()
@@ -210,7 +233,16 @@ module.exports = {
iconURL: interaction.user.avatarURL()
})
.setDescription(
`**${embedIcons.skipped} Skipped track**\n${durationFormat} **[${skippedTrack.title}](${skippedTrack.url})**.`
`**${embedIcons.skipped} Skipped track**\n${durationFormat} **[${skippedTrack.title}](${skippedTrack.url})**` +
`${
queue.repeatMode === 0
? ''
: `\n\n**${
queue.repeatMode === 3
? embedIcons.autoplaying
: embedIcons.looping
} Looping**\nLoop mode is set to ${repeatModeUserString}. You can change it with \`/loop\`.`
}`
)
.setThumbnail(skippedTrack.thumbnail)
.setColor(embedColors.colorSuccess)
+22 -31
View File
@@ -56,36 +56,27 @@ module.exports = {
// change paused state to opposite of current state
queue.node.setPaused(!queue.node.isPaused());
if (queue.node.isPaused()) {
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setAuthor({
name: interaction.member.nickname || interaction.user.username,
iconURL: interaction.user.avatarURL()
})
.setDescription(
`**${embedIcons.pauseResumed} Paused track**\n**${durationFormat} [${queue.currentTrack.title}](${queue.currentTrack.url})**`
)
.setThumbnail(queue.currentTrack.thumbnail)
.setColor(embedColors.colorSuccess)
]
});
} else {
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setAuthor({
name: interaction.member.nickname || interaction.user.username,
iconURL: interaction.user.avatarURL()
})
.setDescription(
`**${embedIcons.pauseResumed} Resumed track**\n**${durationFormat} [${queue.currentTrack.title}](${queue.currentTrack.url})**`
)
.setThumbnail(queue.currentTrack.thumbnail)
.setColor(embedColors.colorSuccess)
]
});
}
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setAuthor({
name:
interaction.member.nickname ||
interaction.user.username,
iconURL: interaction.user.avatarURL()
})
.setDescription(
`**${embedIcons.pauseResumed} ${
queue.node.isPaused()
? 'Paused Track'
: 'Resumed track'
}**\n**${durationFormat} [${
queue.currentTrack.title
}](${queue.currentTrack.url})**`
)
.setThumbnail(queue.currentTrack.thumbnail)
.setColor(embedColors.colorSuccess)
]
});
}
};
+33 -8
View File
@@ -41,7 +41,9 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedIcons.warning} Oops!**\nPage \`${pageIndex + 1}\` is not a valid page number.\n\nThe queue is currently empty, first add some tracks with \`/play\`!`
`**${embedIcons.warning} Oops!**\nPage \`${
pageIndex + 1
}\` is not a valid page number.\n\nThe queue is currently empty, first add some tracks with \`/play\`!`
)
.setColor(embedColors.colorWarning)
]
@@ -74,7 +76,9 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedIcons.warning} Oops!**\nPage \`${pageIndex + 1}\` is not a valid page number.\n\nThere are only a total of \`${totalPages}\` pages in the queue.`
`**${embedIcons.warning} Oops!**\nPage \`${
pageIndex + 1
}\` is not a valid page number.\n\nThere are only a total of \`${totalPages}\` pages in the queue.`
)
.setColor(embedColors.colorWarning)
]
@@ -92,15 +96,34 @@ module.exports = {
? ''
: `\`${track.duration}\``;
return `**${pageIndex * 10 + index + 1}.** ${durationFormat} **[${
track.title
}](${track.url})**`;
return `**${
pageIndex * 10 + index + 1
}.** ${durationFormat} **[${track.title}](${track.url})**`;
})
.join('\n');
}
let currentTrack = queue.currentTrack;
const loopModesFormatted = new Map([
[0, 'disabled'],
[1, 'track'],
[2, 'queue'],
[3, 'autoplay']
]);
const loopModeUserString = loopModesFormatted.get(queue.repeatMode);
let repeatModeString = `${
queue.repeatMode === 0
? ''
: `**${
queue.repeatMode === 3
? embedIcons.autoplay
: embedIcons.loop
} Looping**\nLoop mode is set to ${loopModeUserString}. You can change it with \`/loop\`.\n\n`
}`;
if (!currentTrack) {
return await interaction.editReply({
embeds: [
@@ -112,7 +135,8 @@ module.exports = {
iconURL: interaction.guild.iconURL()
})
.setDescription(
`**${embedIcons.queue} Tracks in queue**\n${queueString}`
`${repeatModeString}` +
`**${embedIcons.queue} Tracks in queue**\n${queueString}`
)
.setFooter({
text: `Page ${pageIndex + 1} of ${totalPages}`
@@ -155,8 +179,9 @@ module.exports = {
? `**[${currentTrack.title}](${currentTrack.url})**`
: 'None') +
`\nRequested by: <@${currentTrack.requestedBy.id}>` +
`\n ${bar}` +
`\n\n**${embedIcons.queue} Tracks in queue**\n${queueString}`
`\n ${bar}\n\n` +
`${repeatModeString}` +
`**${embedIcons.queue} Tracks in queue**\n${queueString}`
)
.setThumbnail(queue.currentTrack.thumbnail)
.setFooter({
+3 -1
View File
@@ -67,7 +67,9 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setAuthor({
name: interaction.member.nickname || interaction.user.username,
name:
interaction.member.nickname ||
interaction.user.username,
iconURL: interaction.user.avatarURL()
})
.setDescription(
+25 -3
View File
@@ -67,7 +67,9 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setAuthor({
name: interaction.member.nickname || interaction.user.username,
name:
interaction.member.nickname ||
interaction.user.username,
iconURL: interaction.user.avatarURL()
})
.setDescription(
@@ -99,15 +101,35 @@ module.exports = {
: `\`${skippedTrack.duration}\``;
queue.node.skip();
const loopModesFormatted = new Map([
[0, 'disabled'],
[1, 'track'],
[2, 'queue'],
[3, 'autoplay']
]);
const loopModeUserString = loopModesFormatted.get(queue.repeatMode);
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setAuthor({
name: interaction.member.nickname || interaction.user.username,
name:
interaction.member.nickname ||
interaction.user.username,
iconURL: interaction.user.avatarURL()
})
.setDescription(
`**${embedIcons.skipped} Skipped track**\n${durationFormat} **[${skippedTrack.title}](${skippedTrack.url})**`
`**${embedIcons.skipped} Skipped track**\n${durationFormat} **[${skippedTrack.title}](${skippedTrack.url})**` +
`${
queue.repeatMode === 0
? ''
: `\n\n**${
queue.repeatMode === 3
? embedIcons.autoplaying
: embedIcons.looping
} Looping**\nLoop mode is set to ${loopModeUserString}. You can change it with \`/loop\`.`
}`
)
.setThumbnail(skippedTrack.thumbnail)
.setColor(embedColors.colorSuccess)
+14 -4
View File
@@ -45,11 +45,17 @@ module.exports = {
const volume = interaction.options.getNumber('percentage');
if (!volume && volume !== 0) {
const currentVolume = queue.node.volume;
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedIcons.volume} Playback volume**\nThe playback volume is currently set to \`${queue.node.volume}%\`.`
`**${
currentVolume === 0
? embedIcons.volumeIsMuted
: embedIcons.volume
} Playback volume**\nThe playback volume is currently set to \`${currentVolume}%\`.`
)
.setColor(embedColors.colorInfo)
]
@@ -72,11 +78,13 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setAuthor({
name: interaction.member.nickname || interaction.user.username,
name:
interaction.member.nickname ||
interaction.user.username,
iconURL: interaction.user.avatarURL()
})
.setDescription(
`**${embedIcons.volumeChanged} Audio muted**\nPlayback audio has been muted, because volume was set to \`${volume}%\`.`
`**${embedIcons.volumeMuted} Audio muted**\nPlayback audio has been muted, because volume was set to \`${volume}%\`.`
)
.setColor(embedColors.colorSuccess)
]
@@ -87,7 +95,9 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setAuthor({
name: interaction.member.nickname || interaction.user.username,
name:
interaction.member.nickname ||
interaction.user.username,
iconURL: interaction.user.avatarURL()
})
.setDescription(
+8
View File
@@ -55,12 +55,20 @@
"previousTrack": "⏮️",
"pauseResumeTrack": "⏯️",
"shuffleQueue": "🔀",
"loop": "🔁",
"loopAction": "🔁",
"autoplay": "♾️",
"autoplayAction": "♾️",
"looping": "🔁",
"autoplaying": "♾️",
"skipped": "⏭️",
"back": "⏮️",
"pauseResumed": "⏯️",
"shuffled": "🔀",
"volume": "🔊",
"volumeIsMuted": "🔇",
"volumeChanged": "🔊",
"volumeMuted": "🔇",
"queue": "🎶"
},
"filterThreadAmount": "2",
+2
View File
@@ -37,6 +37,8 @@ for (const file of systemCommandFiles) {
const player = new Player(client, {
useLegacyFFmpeg: false,
ytdlOptions: {
quality: 'highestaudio',
highWaterMark: 1 << 25,
requestOptions: {
headers: {
cookie: process.env.YOUTUBE_COOKIE || ''
+5 -2
View File
@@ -31,9 +31,12 @@ module.exports = {
memberCount: guild.memberCount
};
})
.slice(0, 50)
.sort((a, b) => b.memberCount - a.memberCount)
.map((guild, index) => `${index + 1}. \`${guild.name} (#${guild.memberCount})\``)
.slice(0, 50)
.map(
(guild, index) =>
`${index + 1}. \`${guild.name} (#${guild.memberCount})\``
)
.join('\n');
let embedDescription = `**${embedIcons.bot} ${