mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-02 14:38:49 +00:00
feat!: Moved source into /src folder
This commit is contained in:
1 parent
6d182c627a
commit
ee274feb2b
20 files changed
+63
-37
No files matched your search
@@ -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;
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -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)
|
||||
]
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -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)
|
||||
]
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -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)
|
||||
]
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -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)
|
||||
]
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -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)
|
||||
]
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -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)
|
||||
]
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -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)
|
||||
]
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -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)
|
||||
]
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -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)
|
||||
]
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -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)
|
||||
]
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,44 @@
|
||||
const path = require('path');
|
||||
const fs = require('node:fs');
|
||||
const logger = require(path.resolve('./src/services/logger.js'));
|
||||
const { REST, Routes } = require('discord.js');
|
||||
require('dotenv').config();
|
||||
|
||||
const commands = [];
|
||||
const commandFiles = fs
|
||||
.readdirSync(path.resolve('./src/commands'))
|
||||
.filter((file) => file.endsWith('.js'));
|
||||
|
||||
for (const file of commandFiles) {
|
||||
const command = require(path.resolve(`./src/commands/${file}`));
|
||||
commands.push(command.data.toJSON());
|
||||
}
|
||||
|
||||
const rest = new REST({ version: '10' }).setToken(
|
||||
process.env.DISCORD_BOT_TOKEN
|
||||
);
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
logger.info('DEPLOYING BOT SLASH COMMANDS');
|
||||
logger.info(
|
||||
commands.map((commands) => {
|
||||
return commands.name;
|
||||
}),
|
||||
'Bot commands found:'
|
||||
);
|
||||
|
||||
logger.info('Started refreshing application (/) bot commands.');
|
||||
|
||||
await rest.put(
|
||||
Routes.applicationCommands(process.env.DISCORD_CLIENT_ID),
|
||||
{
|
||||
body: commands
|
||||
}
|
||||
);
|
||||
|
||||
logger.info('Successfully refreshed application (/) bot commands.');
|
||||
} catch (error) {
|
||||
logger.error(error, 'Failed to refresh application (/) bot commands.');
|
||||
}
|
||||
})();
|
||||
@@ -0,0 +1,53 @@
|
||||
const path = require('path');
|
||||
const fs = require('node:fs');
|
||||
const logger = require(path.resolve('./src/services/logger.js'));
|
||||
const { REST, Routes } = require('discord.js');
|
||||
const { systemServerGuildIds } = require(path.resolve('./config.json'));
|
||||
require('dotenv').config();
|
||||
|
||||
const systemCommands = [];
|
||||
const systemCommandFiles = fs
|
||||
.readdirSync(path.resolve('./src/system-commands'))
|
||||
.filter((file) => file.endsWith('.js'));
|
||||
|
||||
for (const file of systemCommandFiles) {
|
||||
const systemCommand = require(path.resolve(`./src/system-commands/${file}`));
|
||||
systemCommands.push(systemCommand.data.toJSON());
|
||||
}
|
||||
|
||||
const rest = new REST({ version: '10' }).setToken(
|
||||
process.env.DISCORD_BOT_TOKEN
|
||||
);
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
logger.info('DEPLOYING SYSTEM SLASH COMMANDS');
|
||||
logger.info(
|
||||
systemCommands.map((systemCommand) => {
|
||||
return systemCommand.name;
|
||||
}),
|
||||
'System commands found:'
|
||||
);
|
||||
|
||||
logger.info('Started refreshing application (/) system commands.');
|
||||
|
||||
for (const systemServerGuildId of systemServerGuildIds) {
|
||||
await rest.put(
|
||||
Routes.applicationGuildCommands(
|
||||
process.env.DISCORD_CLIENT_ID,
|
||||
systemServerGuildId
|
||||
),
|
||||
{
|
||||
body: systemCommands
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
logger.info('Successfully refreshed application (/) system commands.');
|
||||
} catch (error) {
|
||||
logger.error(
|
||||
error,
|
||||
'Failed to refresh application (/) system commands.'
|
||||
);
|
||||
}
|
||||
})();
|
||||
+215
@@ -0,0 +1,215 @@
|
||||
const fs = require('node:fs');
|
||||
const path = require('path');
|
||||
const Discord = require('discord.js');
|
||||
const logger = require(path.resolve('./src/services/logger.js'));
|
||||
const { EmbedBuilder } = require('discord.js');
|
||||
const { Player, onBeforeCreateStream } = require('discord-player');
|
||||
const { stream } = require('yt-stream');
|
||||
const { embedColors, embedIcons, botInfo } = require(path.resolve(
|
||||
'./config.json'
|
||||
));
|
||||
require('dotenv').config();
|
||||
|
||||
// Setup required permissions for the bot to work
|
||||
const client = new Discord.Client({
|
||||
intents: [
|
||||
Discord.GatewayIntentBits.Guilds,
|
||||
Discord.GatewayIntentBits.GuildVoiceStates
|
||||
]
|
||||
});
|
||||
|
||||
// Setup commands collection and load commands
|
||||
// todo: extract this logic to a separate file
|
||||
client.commands = new Discord.Collection();
|
||||
const commandFiles = fs
|
||||
.readdirSync(path.resolve('./src/commands'))
|
||||
.filter((file) => file.endsWith('.js'));
|
||||
for (const file of commandFiles) {
|
||||
const command = require(path.resolve(`./src/commands/${file}`));
|
||||
client.commands.set(command.data.name, command);
|
||||
}
|
||||
|
||||
const systemCommandFiles = fs
|
||||
.readdirSync(path.resolve('./src/system-commands'))
|
||||
.filter((file) => file.endsWith('.js'));
|
||||
for (const file of systemCommandFiles) {
|
||||
const systemCommand = require(path.resolve(
|
||||
`./src/system-commands/${file}`
|
||||
));
|
||||
client.commands.set(systemCommand.data.name, systemCommand);
|
||||
}
|
||||
|
||||
const player = new Player(client, {
|
||||
useLegacyFFmpeg: false,
|
||||
ytdlOptions: {
|
||||
quality: 'highestaudio',
|
||||
highWaterMark: 1 << 25,
|
||||
requestOptions: {
|
||||
headers: {
|
||||
cookie: process.env.YOUTUBE_COOKIE || ''
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
onBeforeCreateStream(async (track) => {
|
||||
if (track.source === 'youtube') {
|
||||
return (
|
||||
await stream(track.url, {
|
||||
type: 'audio',
|
||||
quality: 'high',
|
||||
highWaterMark: 1 << 25,
|
||||
cookie: process.env.YOUTUBE_COOKIE || ''
|
||||
})
|
||||
).stream;
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
player.on('debug', (message) => {
|
||||
logger.debug(message);
|
||||
});
|
||||
|
||||
player.events.on('debug', (message) => {
|
||||
logger.trace(message);
|
||||
});
|
||||
}
|
||||
|
||||
player.events.on('error', (queue, error) => {
|
||||
// Emitted when the player queue encounters error
|
||||
logger.error(error, 'Player queue error event');
|
||||
});
|
||||
|
||||
player.events.on('playerError', (queue, error) => {
|
||||
// Emitted when the audio player errors while streaming audio track
|
||||
logger.error(error, 'Player audio stream error event');
|
||||
});
|
||||
|
||||
player.events.on('playerStart', (queue, track) => {
|
||||
logger.debug(`playerStart event: Started playing '${track.title}'.`);
|
||||
});
|
||||
|
||||
player.events.on('playerSkip', (queue, track) => {
|
||||
logger.debug(`playerSkip event: Failed to play '${track.title}'.`);
|
||||
});
|
||||
|
||||
client.once('ready', async () => {
|
||||
// This method will load all the extractors from the @discord-player/extractor package
|
||||
await player.extractors.loadDefault();
|
||||
|
||||
logger.info(`discord-player loaded dependencies:\n${player.scanDeps()}`);
|
||||
logger.info(`Logged in as ${client.user.tag}!`);
|
||||
logger.info(
|
||||
`${client.user.tag} is currently added in ${client.guilds.cache.size} guilds`
|
||||
);
|
||||
|
||||
// Set Discord presence status for bot
|
||||
client.user.setActivity('/help', {
|
||||
type: Discord.ActivityType.Watching,
|
||||
name: '/help'
|
||||
});
|
||||
});
|
||||
|
||||
client.once('reconnecting', () => {
|
||||
logger.warn('${client.user.tag} is reconnecting to Discord APIs.');
|
||||
});
|
||||
|
||||
client.once('disconnect', () => {
|
||||
logger.warn(
|
||||
'${client.user.tag} lost connection to Discord APIs. Disconnected.'
|
||||
);
|
||||
});
|
||||
|
||||
client.on('warn', (warning) => {
|
||||
logger.warn(warning, 'Discord client warning event');
|
||||
});
|
||||
|
||||
client.on('error', (error) => {
|
||||
logger.error(error, 'Discord client error event');
|
||||
});
|
||||
|
||||
client.on('guildCreate', (guild) => {
|
||||
logger.info(
|
||||
`Added to guild '${guild.name}' with ${guild.memberCount} members.`
|
||||
);
|
||||
});
|
||||
|
||||
client.on('guildDelete', (guild) => {
|
||||
logger.info(
|
||||
`Removed from guild '${guild.name}' with ${guild.memberCount} members.`
|
||||
);
|
||||
});
|
||||
|
||||
client.on('interactionCreate', async (interaction) => {
|
||||
if (!interaction.isCommand()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const command = client.commands.get(interaction.commandName);
|
||||
if (!command) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const inputTime = new Date();
|
||||
await interaction.deferReply();
|
||||
await command.run({ interaction, client });
|
||||
const outputTime = new Date();
|
||||
const executionTime = outputTime - inputTime;
|
||||
|
||||
if (executionTime > 20000) {
|
||||
// don't send warning message for commands with collector timeouts, as collector timeout happens after 60 seconds
|
||||
if (
|
||||
(interaction.commandName === 'filters' ||
|
||||
interaction.commandName === 'nowplaying') &&
|
||||
executionTime > 55000
|
||||
) {
|
||||
logger.info(
|
||||
`(${interaction.guild.memberCount}) ${interaction.guild.name}> Command '${interaction}' executed in ${executionTime} ms.`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
logger.warn(
|
||||
`(${interaction.guild.memberCount}) ${interaction.guild.name}> Command '${interaction}' took ${executionTime} ms to execute.`
|
||||
);
|
||||
|
||||
return await interaction.followUp({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setDescription(
|
||||
`**${
|
||||
embedIcons.warning
|
||||
} Warning**\nThis command took ${
|
||||
executionTime / 1000
|
||||
} seconds to execute.\n\n_If you experienced problems with the command, please try again._`
|
||||
)
|
||||
.setColor(embedColors.colorWarning)
|
||||
]
|
||||
});
|
||||
} else {
|
||||
logger.info(
|
||||
`(${interaction.guild.memberCount}) ${interaction.guild.name}> Command '${interaction}' executed in ${executionTime} ms.`
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error(
|
||||
error,
|
||||
`(${interaction.guild.memberCount}) ${interaction.guild.name}> Command '${interaction}' failed to execute.`
|
||||
);
|
||||
|
||||
await interaction.followUp({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setDescription(
|
||||
`**${embedIcons.error} Uh-oh... _Something_ went wrong!**\nThere was an unexpected error while trying to execute this command.\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)
|
||||
]
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
client.login(process.env.DISCORD_BOT_TOKEN);
|
||||
@@ -0,0 +1,53 @@
|
||||
const pino = require('pino');
|
||||
require('dotenv').config();
|
||||
|
||||
const transport = pino.transport({
|
||||
targets: [
|
||||
{
|
||||
target: 'pino/file',
|
||||
level: process.env.MINIMUM_LOG_LEVEL,
|
||||
options: {
|
||||
destination: './logs/app-all.log',
|
||||
mkdir: true,
|
||||
sync: false,
|
||||
minLength: 4096
|
||||
}
|
||||
},
|
||||
{
|
||||
target: 'pino/file',
|
||||
level: 'info',
|
||||
options: {
|
||||
destination: './logs/app-info.log',
|
||||
mkdir: true,
|
||||
sync: false,
|
||||
minLength: 4096
|
||||
}
|
||||
},
|
||||
{
|
||||
target: 'pino/file',
|
||||
level: 'error',
|
||||
options: {
|
||||
destination: './logs/app-error.log',
|
||||
mkdir: true,
|
||||
sync: false
|
||||
}
|
||||
},
|
||||
{
|
||||
target: 'pino/file',
|
||||
level: process.env.MINIMUM_LOG_LEVEL_CONSOLE,
|
||||
options: {
|
||||
colorize: true,
|
||||
sync: false
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
module.exports = pino(
|
||||
{
|
||||
level: process.env.MINIMUM_LOG_LEVEL,
|
||||
timestamp: () => `,"timestamp":"${new Date(Date.now()).toISOString()}"`,
|
||||
base: undefined
|
||||
},
|
||||
transport
|
||||
);
|
||||
@@ -0,0 +1,61 @@
|
||||
const path = require('path');
|
||||
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||
const { EmbedBuilder } = require('discord.js');
|
||||
const {
|
||||
embedColors,
|
||||
embedIcons,
|
||||
systemServerGuildIds
|
||||
} = require(path.resolve('./config.json'));
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('guilds')
|
||||
.setDescription('Show list of guilds where bot is added.')
|
||||
.setDMPermission(false),
|
||||
run: async ({ interaction, client }) => {
|
||||
if (!systemServerGuildIds.includes(interaction.guildId)) {
|
||||
return await interaction.editReply({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setDescription(
|
||||
`**${embedIcons.warning} Oops!**\nNo permission to execute this command.\n\nThe command \`${interaction.commandName}\` cannot be executed in this server.`
|
||||
)
|
||||
.setColor(embedColors.colorWarning)
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
let guildsList = client.guilds.cache
|
||||
.map((guild) => {
|
||||
return {
|
||||
name: guild.name,
|
||||
memberCount: guild.memberCount
|
||||
};
|
||||
})
|
||||
.sort((a, b) => b.memberCount - a.memberCount)
|
||||
.slice(0, 50)
|
||||
.map(
|
||||
(guild, index) =>
|
||||
`${index + 1}. \`${guild.name} (#${guild.memberCount})\``
|
||||
)
|
||||
.join('\n');
|
||||
|
||||
let embedDescription = `**${embedIcons.bot} ${
|
||||
client.guilds.cache.size < 50
|
||||
? `Top ${client.guilds.cache.size} guilds`
|
||||
: 'Top 50 guilds'
|
||||
} by member count (${client.guilds.cache.size} total)**\n${guildsList}`;
|
||||
|
||||
if (embedDescription.length >= 4000) {
|
||||
embedDescription = `${embedDescription.slice(0, 3996)}...`;
|
||||
}
|
||||
|
||||
return await interaction.editReply({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setDescription(embedDescription)
|
||||
.setColor(embedColors.colorInfo)
|
||||
]
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,84 @@
|
||||
const path = require('path');
|
||||
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||
const { EmbedBuilder } = require('discord.js');
|
||||
const { useQueue } = require('discord-player');
|
||||
const {
|
||||
embedColors,
|
||||
embedIcons,
|
||||
systemServerGuildIds
|
||||
} = require(path.resolve('./config.json'));
|
||||
const osu = require('node-os-utils');
|
||||
const packageJson = require(path.resolve('./package.json'));
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('status')
|
||||
.setDescription('Show bot status.')
|
||||
.setDMPermission(false),
|
||||
run: async ({ interaction, client }) => {
|
||||
if (!systemServerGuildIds.includes(interaction.guildId)) {
|
||||
return await interaction.editReply({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setDescription(
|
||||
`**${embedIcons.warning} Oops!**\nNo permission to execute this command.\n\nThe command \`${interaction.commandName}\` cannot be executed in this server.`
|
||||
)
|
||||
.setColor(embedColors.colorWarning)
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
const interactionLatency = Date.now() - interaction.createdTimestamp;
|
||||
const uptimeInSeconds = process.uptime();
|
||||
let uptimeDate = new Date(0);
|
||||
uptimeDate.setSeconds(uptimeInSeconds.toFixed(0));
|
||||
const uptimeString = uptimeDate.toISOString().substring(11, 19);
|
||||
const nodeProcessMemUsageInMb = (
|
||||
process.memoryUsage().heapUsed /
|
||||
1024 /
|
||||
1024
|
||||
).toFixed(2);
|
||||
const usedMemoryInMB = Math.ceil(
|
||||
(await osu.mem.info()).usedMemMb
|
||||
).toLocaleString('en-US');
|
||||
const cpuUsage = await osu.cpu.usage();
|
||||
const cpuCores = await osu.cpu.count();
|
||||
const platform = await osu.os.platform();
|
||||
const releaseVersion = packageJson.version;
|
||||
const discordJsVersion = packageJson.dependencies['discord.js'];
|
||||
const discordPlayerVersion = packageJson.dependencies['discord-player'];
|
||||
const discordApiLatency = client.ws.ping;
|
||||
let activeVoiceConnections = 0;
|
||||
client.guilds.cache.forEach((guild) => {
|
||||
const queue = useQueue(guild.id);
|
||||
|
||||
if (queue) {
|
||||
activeVoiceConnections++;
|
||||
}
|
||||
});
|
||||
|
||||
return await interaction.editReply({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setDescription(
|
||||
`**${embedIcons.bot} System and bot status**\n` +
|
||||
`Uptime: \`${uptimeString}\`\n` +
|
||||
`Platform: \`${platform}\`\n` +
|
||||
`CPU cores: \`${cpuCores}\`\n` +
|
||||
`CPU usage: \`${cpuUsage}%\`\n` +
|
||||
`Node.js mem usage: \`${nodeProcessMemUsageInMb} MB\`\n` +
|
||||
`System mem usage: \`${usedMemoryInMB} MB\`\n` +
|
||||
`Bot version: \`v${releaseVersion}\`\n` +
|
||||
`Node.js version: \`${process.version}\`\n` +
|
||||
`Discord.js version: \`${discordJsVersion}\`\n` +
|
||||
`Discord-player version: \`${discordPlayerVersion}\`\n` +
|
||||
`Discord API latency: \`${discordApiLatency} ms\`\n` +
|
||||
`Interaction latency: \`${interactionLatency} ms\`\n` +
|
||||
`Active voice connections: \`${activeVoiceConnections}\`\n` +
|
||||
`Joined guilds: \`${client.guilds.cache.size}\``
|
||||
)
|
||||
.setColor(embedColors.colorInfo)
|
||||
]
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user