mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-02 06:28:54 +00:00
Added /filter command with configurable system options
This commit is contained in:
1 parent
349511c3ba
commit
c7aa9b41c7
3 files changed
+235
-2
No files matched your search
@@ -0,0 +1,181 @@
|
||||
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||
const { useMainPlayer, useQueue } = require('discord-player');
|
||||
const {
|
||||
EmbedBuilder,
|
||||
StringSelectMenuBuilder,
|
||||
StringSelectMenuOptionBuilder,
|
||||
ActionRowBuilder,
|
||||
ButtonBuilder
|
||||
} = require('discord.js');
|
||||
const {
|
||||
embedColors,
|
||||
filterList,
|
||||
filterThreadAmount
|
||||
} = require('../config.json');
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('filters')
|
||||
.setDescription('Toggle various audio filters during playback.'),
|
||||
run: async ({ interaction }) => {
|
||||
if (!interaction.member.voice.channel) {
|
||||
return interaction.editReply({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setDescription(
|
||||
`**Failed**\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(
|
||||
`**Failed**\nThere are no tracks in the queue.`
|
||||
)
|
||||
.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')
|
||||
);
|
||||
|
||||
const response = await interaction.editReply({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setDescription(
|
||||
`**Toggle filters** (beta)\nToggle or disable audio filters for playback.`
|
||||
)
|
||||
.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
|
||||
});
|
||||
|
||||
console.log(confirmation.values);
|
||||
queue.filters.ffmpeg.setInputArgs([
|
||||
'-threads',
|
||||
filterThreadAmount,
|
||||
'-reconnect',
|
||||
'1',
|
||||
'-reconnect_streamed',
|
||||
'1',
|
||||
'-reconnect_delay_max',
|
||||
'5',
|
||||
'-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 interaction.editReply({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setAuthor({
|
||||
name: interaction.user.username,
|
||||
iconURL: interaction.user.avatarURL()
|
||||
})
|
||||
.setDescription(
|
||||
`**Disabled filters**\nDisabled all audio filters.`
|
||||
)
|
||||
.setColor(embedColors.colorSuccess)
|
||||
],
|
||||
components: []
|
||||
});
|
||||
}
|
||||
|
||||
// Enable provided filters
|
||||
queue.filters.ffmpeg.toggle(confirmation.values);
|
||||
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setAuthor({
|
||||
name: interaction.user.username,
|
||||
iconURL: interaction.user.avatarURL()
|
||||
})
|
||||
.setDescription(
|
||||
`**Filters enabled**\nThese filters are now enabled:\n${confirmation.values
|
||||
.map(
|
||||
(enabled) =>
|
||||
`\`${
|
||||
filterList.find(
|
||||
(filter) =>
|
||||
enabled == filter.value
|
||||
).label
|
||||
}\``
|
||||
)
|
||||
.join(', ')}`
|
||||
)
|
||||
.setColor(embedColors.colorSuccess)
|
||||
],
|
||||
components: []
|
||||
});
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setDescription(
|
||||
`**Cancelled**\nNo confirmation received within 1 minute.`
|
||||
)
|
||||
.setColor(embedColors.colorWarning)
|
||||
],
|
||||
components: []
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
+2
-1
@@ -20,7 +20,8 @@ module.exports = {
|
||||
`\`/remove\` - Remove a track from the queue.\n` +
|
||||
`\`/leave\` - Remove bot from voice channel and clear queue.\n` +
|
||||
`\`/queue\` - Show the list of tracks added to the queue.\n` +
|
||||
`\`/volume\` \`[percentage]\` - Show or set the playback volume for tracks.\n`
|
||||
`\`/volume\` \`[percentage]\` - Show or set the playback volume for tracks.\n` +
|
||||
`\`/filters\` - Toggle various audio filters during playback.\n`
|
||||
)
|
||||
.setColor(embedColors.colorInfo)
|
||||
]
|
||||
|
||||
+52
-1
@@ -9,5 +9,56 @@
|
||||
"colorError": "#F23F43",
|
||||
"colorInfo": "#5865F2",
|
||||
"colorNote": "#80848E"
|
||||
}
|
||||
},
|
||||
"filterThreadAmount": "4",
|
||||
"filterList": [
|
||||
{
|
||||
"label": "Bass boost",
|
||||
"value": "bassboost_low",
|
||||
"description": "Boost the bass of the audio.",
|
||||
"emoji": "🔉"
|
||||
},
|
||||
{
|
||||
"label": "Bass boost high",
|
||||
"value": "bassboost",
|
||||
"description": "Boost the bass of the audio a lot.",
|
||||
"emoji": "🔊"
|
||||
},
|
||||
{
|
||||
"label": "Night core",
|
||||
"value": "nightcore",
|
||||
"description": "Speed up the audio (higher pitch).",
|
||||
"emoji": "🐱"
|
||||
},
|
||||
{
|
||||
"label": "Lo-fi",
|
||||
"value": "lofi",
|
||||
"description": "Low fidelity effect (lower quality).",
|
||||
"emoji": "📻"
|
||||
},
|
||||
{
|
||||
"label": "Vaporwave",
|
||||
"value": "vaporwave",
|
||||
"description": "Slow down the audio (lower pitch).",
|
||||
"emoji": "🌸"
|
||||
},
|
||||
{
|
||||
"label": "Ear rape",
|
||||
"value": "earrape",
|
||||
"description": "Extremely loud and distorted audio.",
|
||||
"emoji": "👂"
|
||||
},
|
||||
{
|
||||
"label": "8D",
|
||||
"value": "8D",
|
||||
"description": "Simulate 8D audio effect (surround).",
|
||||
"emoji": "🎧"
|
||||
},
|
||||
{
|
||||
"label": "Treble",
|
||||
"value": "treble",
|
||||
"description": "Increase the high frequencies.",
|
||||
"emoji": "🎼"
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in new issue
Block a user