mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-04 22:15:29 +00:00
9 files changed
+126
-27
No files matched your search
@@ -1,3 +1,4 @@
|
|||||||
|
const logger = require('../../services/logger');
|
||||||
const { embedOptions, playerOptions, botOptions } = require('../../config');
|
const { embedOptions, playerOptions, botOptions } = require('../../config');
|
||||||
const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidation');
|
const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidation');
|
||||||
const { transformQuery } = require('../../utils/validation/searchQueryValidation');
|
const { transformQuery } = require('../../utils/validation/searchQueryValidation');
|
||||||
@@ -20,9 +21,16 @@ module.exports = {
|
|||||||
|
|
||||||
const transformedQuery = await transformQuery(query);
|
const transformedQuery = await transformQuery(query);
|
||||||
|
|
||||||
const searchResult = await player.search(transformedQuery, {
|
let searchResult;
|
||||||
requestedBy: interaction.user
|
|
||||||
});
|
try {
|
||||||
|
searchResult = await player.search(transformedQuery, {
|
||||||
|
requestedBy: interaction.user
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
logger.error('Failed to search for track with player.search()');
|
||||||
|
logger.error(error);
|
||||||
|
}
|
||||||
|
|
||||||
if (!searchResult || searchResult.tracks.length === 0) {
|
if (!searchResult || searchResult.tracks.length === 0) {
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
@@ -66,7 +74,13 @@ module.exports = {
|
|||||||
leaveOnStopCooldown: playerOptions.leaveOnStopCooldown ?? 60000,
|
leaveOnStopCooldown: playerOptions.leaveOnStopCooldown ?? 60000,
|
||||||
maxSize: playerOptions.maxQueueSize ?? 1000,
|
maxSize: playerOptions.maxQueueSize ?? 1000,
|
||||||
maxHistorySize: playerOptions.maxHistorySize ?? 100,
|
maxHistorySize: playerOptions.maxHistorySize ?? 100,
|
||||||
volume: playerOptions.defaultVolume ?? 50
|
volume: playerOptions.defaultVolume ?? 50,
|
||||||
|
metadata: {
|
||||||
|
channel: interaction.channel,
|
||||||
|
client: interaction.client,
|
||||||
|
requestedBy: interaction.user,
|
||||||
|
track: searchResult.tracks[0]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -110,6 +124,9 @@ module.exports = {
|
|||||||
]
|
]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.error('Failed to play track with player.play()');
|
||||||
|
logger.error(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
let queue = useQueue(interaction.guild.id);
|
let queue = useQueue(interaction.guild.id);
|
||||||
|
|||||||
@@ -44,13 +44,14 @@ module.exports = {
|
|||||||
.setDescription(`**${embedOptions.icons.queue} Tracks in queue**\n${queueString}`)
|
.setDescription(`**${embedOptions.icons.queue} Tracks in queue**\n${queueString}`)
|
||||||
.setColor(embedOptions.colors.info)
|
.setColor(embedOptions.colors.info)
|
||||||
.setFooter({
|
.setFooter({
|
||||||
text: 'Page 1 of 1'
|
text: 'Page 1 of 1 (0 tracks)'
|
||||||
})
|
})
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const totalPages = Math.ceil(queue.tracks.data.length / 10) || 1;
|
const queueLength = queue.tracks.data.length;
|
||||||
|
const totalPages = Math.ceil(queueLength / 10) || 1;
|
||||||
|
|
||||||
if (pageIndex > totalPages - 1) {
|
if (pageIndex > totalPages - 1) {
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
@@ -99,6 +100,7 @@ module.exports = {
|
|||||||
} Looping**\nLoop mode is set to ${loopModeUserString}. You can change it with **\`/loop\`**.\n\n`
|
} Looping**\nLoop mode is set to ${loopModeUserString}. You can change it with **\`/loop\`**.\n\n`
|
||||||
}`;
|
}`;
|
||||||
|
|
||||||
|
|
||||||
if (!currentTrack) {
|
if (!currentTrack) {
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
@@ -111,7 +113,7 @@ module.exports = {
|
|||||||
`${repeatModeString}` + `**${embedOptions.icons.queue} Tracks in queue**\n${queueString}`
|
`${repeatModeString}` + `**${embedOptions.icons.queue} Tracks in queue**\n${queueString}`
|
||||||
)
|
)
|
||||||
.setFooter({
|
.setFooter({
|
||||||
text: `Page ${pageIndex + 1} of ${totalPages}`
|
text: `Page ${pageIndex + 1} of ${totalPages} (${queueLength} tracks)`
|
||||||
})
|
})
|
||||||
.setColor(embedOptions.colors.info)
|
.setColor(embedOptions.colors.info)
|
||||||
]
|
]
|
||||||
@@ -148,7 +150,7 @@ module.exports = {
|
|||||||
)
|
)
|
||||||
.setThumbnail(queue.currentTrack.thumbnail)
|
.setThumbnail(queue.currentTrack.thumbnail)
|
||||||
.setFooter({
|
.setFooter({
|
||||||
text: `Page ${pageIndex + 1} of ${totalPages}`
|
text: `Page ${pageIndex + 1} of ${totalPages} (${queueLength} tracks)`
|
||||||
})
|
})
|
||||||
.setColor(embedOptions.colors.info)
|
.setColor(embedOptions.colors.info)
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ module.exports.playerOptions = {
|
|||||||
leaveOnEmpty: true,
|
leaveOnEmpty: true,
|
||||||
leaveOnEmptyCooldown: 300000,
|
leaveOnEmptyCooldown: 300000,
|
||||||
leaveOnEnd: true,
|
leaveOnEnd: true,
|
||||||
leaveonEndCooldown: 300000,
|
leaveOnEndCooldown: 300000,
|
||||||
leaveOnStop: true,
|
leaveOnStop: true,
|
||||||
leaveOnStopCooldown: 300000,
|
leaveOnStopCooldown: 300000,
|
||||||
defaultVolume: 50,
|
defaultVolume: 50,
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ module.exports = {
|
|||||||
new EmbedBuilder()
|
new EmbedBuilder()
|
||||||
.setDescription(
|
.setDescription(
|
||||||
`${embedOptions.icons.warning} **${client.user.tag}** is **\`disconnected\`**!` +
|
`${embedOptions.icons.warning} **${client.user.tag}** is **\`disconnected\`**!` +
|
||||||
`\n<@${systemOptions.systemUserId}>`
|
`\n\n<@${systemOptions.systemUserId}>`
|
||||||
)
|
)
|
||||||
.setColor(embedOptions.colors.warning)
|
.setColor(embedOptions.colors.warning)
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ module.exports = {
|
|||||||
new EmbedBuilder()
|
new EmbedBuilder()
|
||||||
.setDescription(
|
.setDescription(
|
||||||
`${embedOptions.icons.warning} **${client.user.tag}** is **\`reconnecting\`**!` +
|
`${embedOptions.icons.warning} **${client.user.tag}** is **\`reconnecting\`**!` +
|
||||||
`\n<@${systemOptions.systemUserId}>`
|
`\n\n<@${systemOptions.systemUserId}>`
|
||||||
)
|
)
|
||||||
.setColor(embedOptions.colors.warning)
|
.setColor(embedOptions.colors.warning)
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
const logger = require('../../services/logger');
|
|
||||||
|
|
||||||
// Emitted when the player queue encounters error
|
|
||||||
module.exports = {
|
|
||||||
name: 'error',
|
|
||||||
isDebug: false,
|
|
||||||
isPlayerEvent: true,
|
|
||||||
execute: async (queue, error) => {
|
|
||||||
logger.error(error, 'Player queue error event');
|
|
||||||
process.env.NODE_ENV === 'development' ? logger.trace(queue) : null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
const logger = require('../../services/logger');
|
||||||
|
const { embedOptions, systemOptions, botOptions } = require('../../config');
|
||||||
|
const { EmbedBuilder } = require('discord.js');
|
||||||
|
|
||||||
|
// Emitted when the player queue encounters error (general error with queue)
|
||||||
|
module.exports = {
|
||||||
|
name: 'error',
|
||||||
|
isDebug: false,
|
||||||
|
isPlayerEvent: true,
|
||||||
|
execute: async (queue, error) => {
|
||||||
|
logger.error(error, 'player.events.on(\'error\'): Player queue encountered error event');
|
||||||
|
|
||||||
|
await queue.metadata.channel.send({
|
||||||
|
embeds: [
|
||||||
|
new EmbedBuilder()
|
||||||
|
.setDescription(
|
||||||
|
`**${embedOptions.icons.error} Uh-oh... _Something_ went wrong!**\nIt seems there was an issue related to the queue or current track.\n\nIf you performed a command, you can try again.\n\n_If this problem persists, please submit a bug report in the **[support server](${botOptions.serverInviteUrl})**._`
|
||||||
|
)
|
||||||
|
.setColor(embedOptions.colors.error)
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
if (systemOptions.systemMessageChannelId && systemOptions.systemUserId) {
|
||||||
|
await queue.metadata.client.channels.cache.get(systemOptions.systemMessageChannelId).send({
|
||||||
|
embeds: [
|
||||||
|
new EmbedBuilder()
|
||||||
|
.setDescription(
|
||||||
|
`${embedOptions.icons.error} **player.events.on('error')**\n${error.message}` +
|
||||||
|
`\n\n<@${systemOptions.systemUserId}>`
|
||||||
|
)
|
||||||
|
.setColor(embedOptions.colors.error)
|
||||||
|
]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
process.env.NODE_ENV === 'development' ? logger.trace(queue, 'Queue object') : null;
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -1,11 +1,38 @@
|
|||||||
const logger = require('../../services/logger');
|
const logger = require('../../services/logger');
|
||||||
|
const { embedOptions, systemOptions, botOptions } = require('../../config');
|
||||||
|
const { EmbedBuilder } = require('discord.js');
|
||||||
|
|
||||||
|
// Emitted when the player encounters an error while streaming audio track
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'error',
|
name: 'error',
|
||||||
isDebug: false,
|
isDebug: false,
|
||||||
isPlayerEvent: true,
|
isPlayerEvent: true,
|
||||||
execute: async (queue, error) => {
|
execute: async (queue, error) => {
|
||||||
logger.error(error, 'Player queue error event');
|
logger.error(error, 'player.events.on(\'playerError\'): Player error while streaming track');
|
||||||
process.env.NODE_ENV === 'development' ? logger.trace(queue) : null;
|
|
||||||
|
await queue.metadata.channel.send({
|
||||||
|
embeds: [
|
||||||
|
new EmbedBuilder()
|
||||||
|
.setDescription(
|
||||||
|
`**${embedOptions.icons.error} Uh-oh... _Something_ went wrong!**\nIt seems there was an issue while streaming the track.\n\nIf you performed a command, you can try again.\n\n_If this problem persists, please submit a bug report in the **[support server](${botOptions.serverInviteUrl})**._`
|
||||||
|
)
|
||||||
|
.setColor(embedOptions.colors.error)
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
if (systemOptions.systemMessageChannelId && systemOptions.systemUserId) {
|
||||||
|
await queue.metadata.client.channels.cache.get(systemOptions.systemMessageChannelId).send({
|
||||||
|
embeds: [
|
||||||
|
new EmbedBuilder()
|
||||||
|
.setDescription(
|
||||||
|
`${embedOptions.icons.error} **player.events.on('playerError')**\n${error.message}` +
|
||||||
|
`\n\n<@${systemOptions.systemUserId}>`
|
||||||
|
)
|
||||||
|
.setColor(embedOptions.colors.error)
|
||||||
|
]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
process.env.NODE_ENV === 'development' ? logger.trace(queue, 'Queue object') : null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -1,11 +1,38 @@
|
|||||||
const logger = require('../../services/logger');
|
const logger = require('../../services/logger');
|
||||||
|
const { embedOptions, systemOptions, botOptions } = require('../../config');
|
||||||
|
const { EmbedBuilder } = require('discord.js');
|
||||||
|
|
||||||
|
// Emitted when the audio player fails to load the stream for a track
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'playerSkip',
|
name: 'playerSkip',
|
||||||
isDebug: false,
|
isDebug: false,
|
||||||
isPlayerEvent: true,
|
isPlayerEvent: true,
|
||||||
execute: async (queue, track) => {
|
execute: async (queue, track) => {
|
||||||
logger.warn(`playerSkip event: Failed to play '${track.raw.source}'.`);
|
logger.error(`player.events.on('playerSkip'): Failed to play '${track.url}'.`);
|
||||||
process.env.NODE_ENV === 'development' ? logger.trace(queue) : null;
|
|
||||||
|
await queue.metadata.channel.send({
|
||||||
|
embeds: [
|
||||||
|
new EmbedBuilder()
|
||||||
|
.setDescription(
|
||||||
|
`**${embedOptions.icons.error} Uh-oh... _Something_ went wrong!**\nIt seems there was an issue while loading stream for the track.\n\nIf you performed a command, you can try again.\n\n_If this problem persists, please submit a bug report in the **[support server](${botOptions.serverInviteUrl})**._`
|
||||||
|
)
|
||||||
|
.setColor(embedOptions.colors.error)
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
if (systemOptions.systemMessageChannelId && systemOptions.systemUserId) {
|
||||||
|
await queue.metadata.client.channels.cache.get(systemOptions.systemMessageChannelId).send({
|
||||||
|
embeds: [
|
||||||
|
new EmbedBuilder()
|
||||||
|
.setDescription(
|
||||||
|
`${embedOptions.icons.error} **player.events.on('playerSkip')**\n${track.url}` +
|
||||||
|
`\n\n<@${systemOptions.systemUserId}>`
|
||||||
|
)
|
||||||
|
.setColor(embedOptions.colors.error)
|
||||||
|
]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
process.env.NODE_ENV === 'development' ? logger.trace(queue, 'Queue object') : null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Reference in new issue
Block a user