feat!: Moved source into /src folder

This commit is contained in:
Marius Begby committed 2023-07-17 00:08:03 +02:00
1 parent 6d182c627a
commit ee274feb2b
20 files changed
+63 -37

No files matched your search

+186
View File
@@ -0,0 +1,186 @@
const path = require('path');
const { SlashCommandBuilder } = require('@discordjs/builders');
const { useQueue } = require('discord-player');
const {
EmbedBuilder,
StringSelectMenuBuilder,
StringSelectMenuOptionBuilder,
ActionRowBuilder,
ButtonBuilder
} = require('discord.js');
const {
embedColors,
embedIcons,
filterList,
filterThreadAmount
} = require(path.resolve('./config.json'));
module.exports = {
data: new SlashCommandBuilder()
.setName('filters')
.setDescription('Toggle various audio filters during playback.')
.setDMPermission(false),
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 = await useQueue(interaction.guild.id);
if (!queue) {
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedIcons.warning} Oops!**\nThere are no tracks in the queue. First add some tracks with **\`/play\`**!`
)
.setColor(embedColors.colorWarning)
]
});
}
let filterOptions = [];
filterList.forEach((filter) => {
let isEnabled = false;
if (queue.filters.ffmpeg.filters.includes(filter.value)) {
isEnabled = true;
}
filterOptions.push(
new StringSelectMenuOptionBuilder()
.setLabel(filter.label)
.setDescription(filter.description)
.setValue(filter.value)
.setEmoji(filter.emoji)
.setDefault(isEnabled)
);
});
const filterSelect = new StringSelectMenuBuilder()
.setCustomId('filters')
.setPlaceholder('Select multiple options.')
.setMinValues(0)
.setMaxValues(filterOptions.length)
.addOptions(filterOptions);
const filterActionRow = new ActionRowBuilder().addComponents(
filterSelect
);
const disableFiltersActionRow = new ActionRowBuilder().addComponents(
new ButtonBuilder()
.setCustomId('disable-filters')
.setLabel('Disable all filters')
.setStyle('Secondary')
.setEmoji(embedIcons.disable)
);
const response = await interaction.editReply({
embeds: [
new EmbedBuilder()
.setDescription(
`**Toggle filters** ${embedIcons.beta}\nEnable or disable audio filters for playback from the menu.`
)
.setColor(embedColors.colorInfo)
],
components: [filterActionRow, disableFiltersActionRow]
});
const collectorFilter = (i) => i.user.id === interaction.user.id;
try {
const confirmation = await response.awaitMessageComponent({
filter: collectorFilter,
time: 60000
});
confirmation.deferUpdate();
queue.filters.ffmpeg.setInputArgs([
'-threads',
filterThreadAmount,
'-reconnect',
'1',
'-reconnect_streamed',
'1',
'-reconnect_delay_max',
'10',
'-vn'
]);
// Reset filters before enabling provided filters
if (queue.filters.ffmpeg.filters.length > 0) {
queue.filters.ffmpeg.setFilters(false);
}
if (
confirmation.customId === 'disable-filters' ||
confirmation.values.length === 0
) {
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setAuthor({
name:
interaction.member.nickname ||
interaction.user.username,
iconURL: interaction.user.avatarURL()
})
.setDescription(
`**${embedIcons.success} Disabled filters**\nAll audio filters have been disabled.`
)
.setColor(embedColors.colorSuccess)
],
components: []
});
}
// Enable provided filters
queue.filters.ffmpeg.toggle(confirmation.values);
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setAuthor({
name:
interaction.member.nickname ||
interaction.user.username,
iconURL: interaction.user.avatarURL()
})
.setDescription(
`**${
embedIcons.success
} Filters toggled**\nNow using these filters:\n${confirmation.values
.map(
(enabled) =>
`\`${
filterList.find(
(filter) =>
enabled == filter.value
).label
}\``
)
.join(', ')}.`
)
.setColor(embedColors.colorSuccess)
],
components: []
});
} catch (e) {
if (e.code === 'InteractionCollectorError') {
return;
}
throw e;
}
}
};
+35
View File
@@ -0,0 +1,35 @@
const path = require('path');
const { SlashCommandBuilder } = require('@discordjs/builders');
const { EmbedBuilder } = require('discord.js');
const { embedColors, embedIcons, botInfo } = require(path.resolve('./config.json'));
module.exports = {
data: new SlashCommandBuilder()
.setName('help')
.setDescription('Show a list of commands and their usage.')
.setDMPermission(false),
run: async ({ interaction }) => {
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setDescription(
`${embedIcons.rule} **List of commands**\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`** - Show information about the track currently playing.\n' +
`- **\`/seek\` \`duration\`** - ${embedIcons.new} Seek to a specified duration in the current track.\n` +
`- **\`/loop\` \`mode\`** - ${embedIcons.beta} Toggle looping a track, the whole queue or autoplay.\n` +
'- **`/filters`** - Toggle various audio filters during playback.\n' +
'- **`/volume` `[percentage]`** - Show or set the playback volume for tracks.\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})**`
)
.setColor(embedColors.colorInfo)
]
});
}
};
+63
View File
@@ -0,0 +1,63 @@
const path = require('path');
const { SlashCommandBuilder } = require('@discordjs/builders');
const { useQueue } = require('discord-player');
const { EmbedBuilder } = require('discord.js');
const { embedColors, embedIcons } = require(path.resolve('./config.json'));
module.exports = {
data: new SlashCommandBuilder()
.setName('leave')
.setDescription(
'Clear the track queue and remove the bot from voice channel.'
)
.setDMPermission(false),
// todo, allow command to be executed if bot is only member in voice channel
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!**\n_Hmm.._ It seems I am not in a voice channel!`
)
.setColor(embedColors.colorWarning)
]
});
}
if (!queue.deleted) {
queue.delete();
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setAuthor({
name:
interaction.member.nickname ||
interaction.user.username,
iconURL: interaction.user.avatarURL()
})
.setDescription(
`**${embedIcons.success} Leaving channel**\nCleared the track queue and left voice channel.\n\nTo play more music, use the **\`/play\`** command!`
)
.setColor(embedColors.colorSuccess)
]
});
}
}
};
+157
View File
@@ -0,0 +1,157 @@
const path = require('path');
const { SlashCommandBuilder } = require('@discordjs/builders');
const { useQueue } = require('discord-player');
const { EmbedBuilder } = require('discord.js');
const { embedColors, embedIcons, botInfo } = require(path.resolve('./config.json'));
module.exports = {
data: new SlashCommandBuilder()
.setName('loop')
.setDescription('Toggle looping a track, the whole queue or autoplay.')
.setDMPermission(false)
.addStringOption((option) =>
option
.setName('mode')
.setDescription('Mode to set for looping.')
.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)
]
});
}
};
+272
View File
@@ -0,0 +1,272 @@
const path = require('path');
const { SlashCommandBuilder } = require('@discordjs/builders');
const { useQueue } = require('discord-player');
const { EmbedBuilder, ActionRowBuilder, ButtonBuilder } = require('discord.js');
const {
embedColors,
embedIcons,
progressBarOptions
} = require(path.resolve('./config.json'));
module.exports = {
data: new SlashCommandBuilder()
.setName('nowplaying')
.setDescription('Show information about the track currently playing.')
.setDMPermission(false),
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)
]
});
}
if (!queue.currentTrack) {
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedIcons.warning} Oops!**\nThere is nothing currently playing. First add some tracks with **\`/play\`**!`
)
.setColor(embedColors.colorWarning)
]
});
}
const sourceStringsFormatted = new Map([
['youtube', 'YouTube'],
['soundcloud', 'SoundCloud'],
['spotify', 'Spotify'],
['apple_music', 'Apple Music'],
['arbitrary', 'Direct source']
]);
const sourceIcons = new Map([
['youtube', embedIcons.sourceYouTube],
['soundcloud', embedIcons.sourceSoundCloud],
['spotify', embedIcons.sourceSpotify],
['apple_music', embedIcons.sourceAppleMusic],
['arbitrary', embedIcons.sourceArbitrary]
]);
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 &&
currentTrack.metadata.bridge.views !== 0 &&
currentTrack.metadata.bridge.views !== undefined
) {
plays = currentTrack.metadata.bridge.views;
} else if (plays === 0) {
plays = 'Unavailable';
}
const source =
sourceStringsFormatted.get(currentTrack.raw.source) ??
'Unavailable';
const queueLength = queue.tracks.data.length;
const timestamp = queue.node.getTimestamp();
let bar = `**\`${
timestamp.current.label
}\`** ${queue.node.createProgressBar({
queue: false,
length: progressBarOptions.length ?? 12,
timecodes: progressBarOptions.timecodes ?? false,
indicator: progressBarOptions.indicator ?? '🔘',
leftChar: progressBarOptions.leftChar ?? '▬',
rightChar: progressBarOptions.rightChar ?? '▬'
})} **\`${timestamp.total.label}\`**`;
if (
currentTrack.raw.duration === 0 ||
currentTrack.duration === '0:00'
) {
bar = 'No duration available.';
}
const nowPlayingActionRow = new ActionRowBuilder().addComponents(
new ButtonBuilder()
.setCustomId('nowplaying-skip')
.setLabel('Skip track')
.setStyle('Secondary')
.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()
.setAuthor({
name: `Channel: ${queue.channel.name} (${
queue.channel.bitrate / 1000
}kbps)`,
iconURL: interaction.guild.iconURL()
})
.setDescription(
(queue.node.isPaused()
? '**Currently Paused**\n'
: `**${embedIcons.audioPlaying} Now Playing**\n`) +
`**[${currentTrack.title}](${currentTrack.url})**` +
`\nRequested by: <@${currentTrack.requestedBy.id}>` +
`\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(
{
name: '**Author**',
value: author,
inline: true
},
{
name: '**Plays**',
value: plays.toLocaleString('en-US'),
inline: true
},
{
name: '**Audio source**',
value: `**${sourceIcons.get(
currentTrack.raw.source
)} [${source}](${currentTrack.url})**`,
inline: true
}
)
.setFooter({
text: queueLength
? `${queueLength} other tracks in the queue...`
: ' '
})
.setThumbnail(queue.currentTrack.thumbnail)
.setColor(embedColors.colorInfo)
],
components: [nowPlayingActionRow]
});
const collectorFilter = (i) => i.user.id === interaction.user.id;
try {
const confirmation = await response.awaitMessageComponent({
filter: collectorFilter,
time: 60000
});
confirmation.deferUpdate();
if (confirmation.customId === 'nowplaying-skip') {
if (
!queue ||
(queue.tracks.data.length === 0 && !queue.currentTrack)
) {
return await interaction.followUp({
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedIcons.warning} Oops!**\nThere is nothing currently playing. First add some tracks with **\`/play\`**!`
)
.setColor(embedColors.colorWarning)
],
components: []
});
}
if (queue.currentTrack !== currentTrack) {
return await interaction.followUp({
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedIcons.warning} Oops!**\nThis track has already been skipped or is no longer playing.`
)
.setColor(embedColors.colorWarning)
],
components: []
});
}
const skippedTrack = queue.currentTrack;
let durationFormat =
skippedTrack.raw.duration === 0 ||
skippedTrack.duration === '0:00'
? ''
: `\`${skippedTrack.duration}\``;
queue.node.skip();
const repeatModeUserString = loopModesFormatted.get(
queue.repeatMode
);
return await interaction.followUp({
embeds: [
new EmbedBuilder()
.setAuthor({
name:
interaction.member.nickname ||
interaction.user.username,
iconURL: interaction.user.avatarURL()
})
.setDescription(
`**${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)
],
components: []
});
}
} catch (e) {
if (e.code === 'InteractionCollectorError') {
return;
}
throw e;
}
}
};
+83
View File
@@ -0,0 +1,83 @@
const path = require('path');
const { SlashCommandBuilder } = require('@discordjs/builders');
const { useQueue } = require('discord-player');
const { EmbedBuilder } = require('discord.js');
const { embedColors, embedIcons } = require(path.resolve('./config.json'));
module.exports = {
data: new SlashCommandBuilder()
.setName('pause')
.setDescription('Pause or resume the current track.')
.setDMPermission(false),
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)
]
});
}
if (!queue.currentTrack) {
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedIcons.warning} Oops!**\nThere is nothing currently playing. First add some tracks with **\`/play\`**!`
)
.setColor(embedColors.colorWarning)
]
});
}
let durationFormat =
queue.currentTrack.raw.duration === 0 ||
queue.currentTrack.duration === '0:00'
? ''
: `\`${queue.currentTrack.duration}\``;
// change paused state to opposite of current state
queue.node.setPaused(!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} ${
queue.node.isPaused()
? 'Paused Track'
: 'Resumed track'
}**\n**${durationFormat} [${
queue.currentTrack.title
}](${queue.currentTrack.url})**`
)
.setThumbnail(queue.currentTrack.thumbnail)
.setColor(embedColors.colorSuccess)
]
});
}
};
+232
View File
@@ -0,0 +1,232 @@
const path = require('path');
const { SlashCommandBuilder } = require('@discordjs/builders');
const { useMainPlayer, useQueue } = require('discord-player');
const { EmbedBuilder } = require('discord.js');
const {
embedColors,
embedIcons,
playerOptions,
botInfo
} = require(path.resolve('./config.json'));
module.exports = {
data: new SlashCommandBuilder()
.setName('play')
.setDescription(
'Add a track or playlist to the queue by searching or url.'
)
.setDMPermission(false)
.addStringOption((option) =>
option
.setName('query')
.setDescription('Search query or URL.')
.setRequired(true)
),
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 player = useMainPlayer();
const query = interaction.options.getString('query');
const searchResult = await player.search(query, {
requestedBy: interaction.user
});
if (!searchResult || searchResult.tracks.length === 0) {
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedIcons.warning} No track found**\nNo results found for \`${query}\`.\n\nIf you specified a URL, please make sure it is valid and public.`
)
.setColor(embedColors.colorWarning)
]
});
}
if (
searchResult.tracks[0].raw.live &&
searchResult.tracks[0].raw.duration === 0 &&
searchResult.tracks[0].source === 'youtube'
) {
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedIcons.warning} Unsupported audio source**\nYouTube live streams are currently not supported. This is due to issues with extracting audio from the livestream.\n\n_If you think this message is incorrect, please submit a bug report in the **[support server](${botInfo.supportServerInviteUrl})**._`
)
.setColor(embedColors.colorWarning)
]
});
}
let track;
try {
({ track } = await player.play(
interaction.member.voice.channel,
searchResult,
{
requestedBy: interaction.user,
nodeOptions: {
leaveOnEmpty: playerOptions.leaveOnEmpty ?? true,
leaveOnEmptyCooldown:
playerOptions.leaveOnEmptyCooldown ?? 60000,
leaveOnEnd: playerOptions.leaveOnEnd ?? true,
leaveOnEndCooldown:
playerOptions.leaveOnEndCooldown ?? 60000,
leaveOnStop: playerOptions.leaveOnStop ?? true,
leaveOnStopCooldown:
playerOptions.leaveOnStopCooldown ?? 60000,
maxSize: playerOptions.maxQueueSize ?? 1000,
maxHistorySize: playerOptions.maxHistorySize ?? 100,
volume: playerOptions.defaultVolume ?? 50
}
}
));
} catch (error) {
if (error.message.includes('Sign in to confirm your age')) {
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedIcons.warning} Cannot retrieve audio for track**\nThis audio source is age restricted and requires login to access. Because of this I cannot retrieve the audio for the track.\n\n_If you think this message is incorrect, please submit a bug report in the **[support server](${botInfo.supportServerInviteUrl})**._`
)
.setColor(embedColors.colorWarning)
]
});
}
if (
(error.type === 'TypeError' &&
(error.message.includes(
'Cannot read properties of null (reading \'createStream\')'
) ||
error.message.includes(
'Failed to fetch resources for ytdl streaming'
))) ||
error.message.includes(
'Could not extract stream for this track'
)
) {
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedIcons.error} Uh-oh... Failed to add track!**\nAfter finding a result, I was unable to retrieve audio for the track.\n\nYou can try to perform the command again.\n\n_If you think this message is incorrect, please submit a bug report in the **[support server](${botInfo.supportServerInviteUrl})**._`
)
.setColor(embedColors.colorError)
]
});
}
if (error.message === 'Cancelled') {
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedIcons.error} Uh-oh... Failed to add track!**\nSomething unexpected happened and the operation was cancelled.\n\nYou can try to perform the command again.\n\n_If you think this message is incorrect, please submit a bug report in the **[support server](${botInfo.supportServerInviteUrl})**._`
)
.setColor(embedColors.colorError)
]
});
}
}
let queue = useQueue(interaction.guild.id);
if (!queue) {
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedIcons.error} Uh-oh... Failed to add track!**\nThere was an issue adding this track to the queue.\n\nYou can try to perform the command again.\n\n_If this problem persists, please submit a bug report in the **[support server](${botInfo.supportServerInviteUrl})**._`
)
.setColor(embedColors.colorError)
]
});
}
if (track.source === 'arbitrary') {
track.thumbnail =
'https://raw.githubusercontent.com/mariusbegby/cadence-discord-bot/main/assets/logo-rounded-128px.png';
}
let durationFormat =
track.raw.duration === 0 || track.duration === '0:00'
? ''
: `\`${track.duration}\``;
if (searchResult.playlist && searchResult.tracks.length > 1) {
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setAuthor({
name:
interaction.member.nickname ||
interaction.user.username,
iconURL: interaction.user.avatarURL()
})
.setDescription(
`**${
embedIcons.success
} Added playlist to queue**\n**${durationFormat} [${
track.title
}](${track.url})**\n\nAnd **${
searchResult.tracks.length - 1
}** more tracks... **\`/queue\`** to view all.`
)
.setThumbnail(track.thumbnail)
.setColor(embedColors.colorSuccess)
]
});
}
if (queue.currentTrack === track) {
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setAuthor({
name:
interaction.member.nickname ||
interaction.member.nickname ||
interaction.user.username,
iconURL: interaction.user.avatarURL()
})
.setDescription(
`**${embedIcons.audioStartedPlaying} Started playing**\n**${durationFormat} [${track.title}](${track.url})**`
)
.setThumbnail(track.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.success} **Added to queue**\n**${durationFormat} [${track.title}](${track.url})**`
)
.setThumbnail(track.thumbnail)
.setColor(embedColors.colorSuccess)
]
});
}
};
+196
View File
@@ -0,0 +1,196 @@
const path = require('path');
const { SlashCommandBuilder } = require('@discordjs/builders');
const { useQueue } = require('discord-player');
const { EmbedBuilder } = require('discord.js');
const {
embedColors,
embedIcons,
progressBarOptions
} = require(path.resolve('./config.json'));
module.exports = {
data: new SlashCommandBuilder()
.setName('queue')
.setDescription('Show the list of tracks added to the queue.')
.setDMPermission(false)
.addNumberOption((option) =>
option
.setName('page')
.setDescription('Page number of the queue')
.setMinValue(1)
),
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 pageIndex = (interaction.options.getNumber('page') || 1) - 1;
const queue = useQueue(interaction.guild.id);
let queueString = '';
if (!queue) {
if (pageIndex >= 1) {
return await interaction.editReply({
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\`**!`
)
.setColor(embedColors.colorWarning)
]
});
}
queueString = 'The queue is empty, add some tracks with **`/play`**!';
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setAuthor({
name: interaction.guild.name,
iconURL: interaction.guild.iconURL()
})
.setDescription(
`**${embedIcons.queue} Tracks in queue**\n${queueString}`
)
.setColor(embedColors.colorInfo)
.setFooter({
text: 'Page 1 of 1'
})
]
});
}
const totalPages = Math.ceil(queue.tracks.data.length / 10) || 1;
if (pageIndex > totalPages - 1) {
return await interaction.editReply({
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.`
)
.setColor(embedColors.colorWarning)
]
});
}
if (queue.tracks.data.length === 0) {
queueString = 'The queue is empty, add some tracks with **`/play`**!';
} else {
queueString = queue.tracks.data
.slice(pageIndex * 10, pageIndex * 10 + 10)
.map((track, index) => {
let durationFormat =
track.raw.duration === 0 || track.duration === '0:00'
? ''
: `\`${track.duration}\``;
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: [
new EmbedBuilder()
.setAuthor({
name: `Channel: ${queue.channel.name} (${
queue.channel.bitrate / 1000
}kbps)`,
iconURL: interaction.guild.iconURL()
})
.setDescription(
`${repeatModeString}` +
`**${embedIcons.queue} Tracks in queue**\n${queueString}`
)
.setFooter({
text: `Page ${pageIndex + 1} of ${totalPages}`
})
.setColor(embedColors.colorInfo)
]
});
} else {
const timestamp = queue.node.getTimestamp();
let bar = `**\`${
timestamp.current.label
}\`** ${queue.node.createProgressBar({
queue: false,
length: progressBarOptions.length ?? 12,
timecodes: progressBarOptions.timecodes ?? false,
indicator: progressBarOptions.indicator ?? '🔘',
leftChar: progressBarOptions.leftChar ?? '▬',
rightChar: progressBarOptions.rightChar ?? '▬'
})} **\`${timestamp.total.label}\`**`;
if (
currentTrack.raw.duration === 0 ||
currentTrack.duration === '0:00'
) {
bar = '_No duration available._';
}
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setAuthor({
name: `Channel: ${queue.channel.name} (${
queue.channel.bitrate / 1000
}kbps)`,
iconURL: interaction.guild.iconURL()
})
.setDescription(
`**${embedIcons.audioPlaying} Now playing**\n` +
(currentTrack
? `**[${currentTrack.title}](${currentTrack.url})**`
: 'None') +
`\nRequested by: <@${currentTrack.requestedBy.id}>` +
`\n ${bar}\n\n` +
`${repeatModeString}` +
`**${embedIcons.queue} Tracks in queue**\n${queueString}`
)
.setThumbnail(queue.currentTrack.thumbnail)
.setFooter({
text: `Page ${pageIndex + 1} of ${totalPages}`
})
.setColor(embedColors.colorInfo)
]
});
}
}
};
+84
View File
@@ -0,0 +1,84 @@
const path = require('path');
const { SlashCommandBuilder } = require('@discordjs/builders');
const { useQueue } = require('discord-player');
const { EmbedBuilder } = require('discord.js');
const { embedColors, embedIcons } = require(path.resolve('./config.json'));
module.exports = {
data: new SlashCommandBuilder()
.setName('remove')
.setDescription('Remove a specific track from the queue.')
.setDMPermission(false)
.addNumberOption((option) =>
option
.setName('tracknumber')
.setDescription('Track number to remove from queue.')
.setMinValue(1)
.setRequired(true)
),
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 removeTrackNumber = interaction.options.getNumber('tracknumber');
if (removeTrackNumber > queue.tracks.data.length) {
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedIcons.warning} Oops!**\nTrack \`${removeTrackNumber}\` is not a valid track number. There are a total of\`${queue.tracks.data.length}\` tracks in the queue.\n\nView tracks added to the queue with **\`/queue\`**.`
)
.setColor(embedColors.colorWarning)
]
});
}
// Remove specified track number from queue
const removedTrack = queue.node.remove(removeTrackNumber - 1);
let durationFormat =
removedTrack.raw.duration === 0 || removedTrack.duration === '0:00'
? ''
: `\`${removedTrack.duration}\``;
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setAuthor({
name:
interaction.member.nickname ||
interaction.user.username,
iconURL: interaction.user.avatarURL()
})
.setDescription(
`**${embedIcons.success} Removed track**\n**${durationFormat} [${removedTrack.title}](${removedTrack.url})**`
)
.setThumbnail(removedTrack.thumbnail)
.setColor(embedColors.colorSuccess)
]
});
}
};
+169
View File
@@ -0,0 +1,169 @@
const path = require('path');
const { SlashCommandBuilder } = require('@discordjs/builders');
const { useQueue } = require('discord-player');
const { EmbedBuilder } = require('discord.js');
const { embedColors, embedIcons } = require(path.resolve('./config.json'));
module.exports = {
data: new SlashCommandBuilder()
.setName('seek')
.setDescription('Seek to a specified duration in the current track.')
.setDMPermission(false)
.addStringOption((option) =>
option
.setName('duration')
.setDescription(
'Duration in format 00:00:00 (HH:mm:ss) to seek to.'
)
.setRequired(true)
),
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)
]
});
}
if (!queue.currentTrack) {
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedIcons.warning} Oops!**\nThere is nothing currently playing. First add some tracks with **\`/play\`**!`
)
.setColor(embedColors.colorWarning)
]
});
}
const durationInput = interaction.options.getString('duration');
let durationArray = durationInput.split(':');
switch (durationArray.length) {
case 1:
durationArray.unshift('00', '00');
break;
case 2:
durationArray.unshift('00');
break;
default:
break;
}
if (durationArray.length === 0 || durationArray.length > 3) {
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedIcons.warning} Oops!**\nYou entered an invalid duration format, \`${durationString}\`.\n\nPlease use the format \`HH:mm:ss\`, \`mm:ss\` or \`ss\`, where \`HH\` is hours, \`mm\` is minutes and \`ss\` is seconds.\n\n**Examples:**\n` +
'- `/seek` **`1:24:12`** - Seek to 1 hour, 24 minutes and 12 seconds.\n' +
'- `/seek` **`3:27`** - Seek to 3 minutes and 27 seconds.\n' +
'- `/seek` **`42`** - Seek to 42 seconds.'
)
.setColor(embedColors.colorWarning)
]
});
}
durationArray = durationArray.map((value) => {
return value.padStart(2, '0');
});
const durationString = durationArray.join(':');
let validElements = durationArray.every((value) => {
return value.length === 2;
});
if (!validElements) {
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedIcons.warning} Oops!**\nYou entered an invalid duration format, \`${durationString}\`.\n\nPlease use the format \`HH:mm:ss\`, \`mm:ss\` or \`ss\`, where \`HH\` is hours, \`mm\` is minutes and \`ss\` is seconds.\n\n**Examples:**\n` +
'- `/seek` **`1:24:12`** - Seek to 1 hour, 24 minutes and 12 seconds.\n' +
'- `/seek` **`3:27`** - Seek to 3 minutes and 27 seconds.\n' +
'- `/seek` **`42`** - Seek to 42 seconds.'
)
.setColor(embedColors.colorWarning)
]
});
}
// Now array should only be 3 elements long, all with 2 characters, e.g. ['00', '00', '00'].
// Regex can now validate if this is a valid duration format. E.g. check if the first element is 0-23, second element is 0-59 and third element is 0-59.
const regex = new RegExp('([0-1][0-9]|2[0-3]):?[0-5][0-9]:?[0-5][0-9]');
const isValidDuration = regex.test(durationString);
if (!isValidDuration) {
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedIcons.warning} Oops!**\nYou entered an invalid duration format, \`${durationString}\`.\n\nPlease use the format \`HH:mm:ss\`, \`mm:ss\` or \`ss\`, where \`HH\` is hours, \`mm\` is minutes and \`ss\` is seconds.\n\n**Examples:**\n` +
'- `/seek` **`1:24:12`** - Seek to 1 hour, 24 minutes and 12 seconds.\n' +
'- `/seek` **`3:27`** - Seek to 3 minutes and 27 seconds.\n' +
'- `/seek` **`42`** - Seek to 42 seconds.'
)
.setColor(embedColors.colorWarning)
]
});
}
const currentTrackMaxDurationInMs = queue.currentTrack.durationMS;
const durationInMilliseconds =
durationArray[0] * 3600000 +
durationArray[1] * 60000 +
durationArray[2] * 1000;
if (durationInMilliseconds > currentTrackMaxDurationInMs - 1000) {
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedIcons.warning} Oops!**\nYou entered **\`${durationString}\`**, which is a duration that is longer than the duration for the current track.\n\nPlease try a duration that is less than the duration of the track (**\`${queue.currentTrack.duration}\`**).`
)
.setColor(embedColors.colorWarning)
]
});
}
queue.node.seek(durationInMilliseconds);
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setAuthor({
name:
interaction.member.nickname ||
interaction.user.username,
iconURL: interaction.user.avatarURL()
})
.setDescription(
`**${embedIcons.success} Seeking to duration**\nSeeking to **\`${durationString}\`** in current track.`
)
.setThumbnail(queue.currentTrack.thumbnail)
.setColor(embedColors.colorSuccess)
]
});
}
};
+141
View File
@@ -0,0 +1,141 @@
const path = require('path');
const { SlashCommandBuilder } = require('@discordjs/builders');
const { useQueue } = require('discord-player');
const { EmbedBuilder } = require('discord.js');
const { embedColors, embedIcons } = require(path.resolve('./config.json'));
module.exports = {
data: new SlashCommandBuilder()
.setName('skip')
.setDescription('Skip current or specified track.')
.setDMPermission(false)
.addNumberOption((option) =>
option
.setName('tracknumber')
.setDescription('Track number to skip to in the queue.')
.setMinValue(1)
),
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 skipToTrack = interaction.options.getNumber('tracknumber');
if (skipToTrack) {
if (skipToTrack > queue.tracks.data.length) {
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedIcons.warning} Oops!**\nThere are only \`${queue.tracks.data.length}\` tracks in the queue. You cannot skip to track \`${skipToTrack}\`.\n\nView tracks added to the queue with **\`/queue\`**.`
)
.setColor(embedColors.colorWarning)
]
});
} else {
const skippedTrack = queue.currentTrack;
let durationFormat =
skippedTrack.raw.duration === 0 ||
skippedTrack.duration === '0:00'
? ''
: `\`${skippedTrack.duration}\``;
queue.node.skipTo(skipToTrack - 1);
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setAuthor({
name:
interaction.member.nickname ||
interaction.user.username,
iconURL: interaction.user.avatarURL()
})
.setDescription(
`**${embedIcons.skipped} Skipped track**\n**${durationFormat} [${skippedTrack.title}](${skippedTrack.url})**`
)
.setThumbnail(skippedTrack.thumbnail)
.setColor(embedColors.colorSuccess)
]
});
}
} else {
if (queue.tracks.data.length === 0 && !queue.currentTrack) {
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedIcons.warning} Oops!**\nThere is nothing currently playing. First add some tracks with **\`/play\`**!`
)
.setColor(embedColors.colorWarning)
]
});
}
const skippedTrack = queue.currentTrack;
let durationFormat =
skippedTrack.raw.duration === 0 ||
skippedTrack.duration === '0:00'
? ''
: `\`${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,
iconURL: interaction.user.avatarURL()
})
.setDescription(
`**${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)
]
});
}
}
};
+112
View File
@@ -0,0 +1,112 @@
const path = require('path');
const { SlashCommandBuilder } = require('@discordjs/builders');
const { useQueue } = require('discord-player');
const { EmbedBuilder } = require('discord.js');
const { embedColors, embedIcons } = require(path.resolve('./config.json'));
module.exports = {
data: new SlashCommandBuilder()
.setName('volume')
.setDescription('Show or set the playback volume for tracks.')
.setDMPermission(false)
.addNumberOption((option) =>
option
.setName('percentage')
.setDescription('Set volume percentage from 1% to 100%.')
.setMinValue(0)
.setMaxValue(100)
),
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 volume = interaction.options.getNumber('percentage');
if (!volume && volume !== 0) {
const currentVolume = queue.node.volume;
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setDescription(
`**${
currentVolume === 0
? embedIcons.volumeIsMuted
: embedIcons.volume
} Playback volume**\nThe playback volume is currently set to \`${currentVolume}%\`.`
)
.setColor(embedColors.colorInfo)
]
});
} else if (volume > 100 || volume < 0) {
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedIcons.warning} Oops!**\nYou cannot set the volume to \`${volume}\`, please pick a value betwen \`1\`% and \`100\`%.`
)
.setColor(embedColors.colorWarning)
]
});
} else {
queue.node.setVolume(volume);
if (volume === 0) {
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setAuthor({
name:
interaction.member.nickname ||
interaction.user.username,
iconURL: interaction.user.avatarURL()
})
.setDescription(
`**${embedIcons.volumeMuted} Audio muted**\nPlayback audio has been muted, because volume was set to \`${volume}%\`.`
)
.setColor(embedColors.colorSuccess)
]
});
}
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setAuthor({
name:
interaction.member.nickname ||
interaction.user.username,
iconURL: interaction.user.avatarURL()
})
.setDescription(
`**${embedIcons.volumeChanged} Volume changed**\nPlayback volume has been changed to \`${volume}%\`.`
)
.setColor(embedColors.colorSuccess)
]
});
}
}
};