Hi, so i want to create a discord bot command in JS where it finds songs and your able…
- User
Hi, so i want to create a discord bot command in JS where it finds songs and your able to download them from a file the bot gives, so i have a bunch of unreleased Juice WRLD songs and they are in a folder in my bot called "Songs" i want the command to be like "/find song [Baby]" and then it creates a embed with the song information but if there is songs with names like it says like "Mutiple versions found" with a dropdown where u can pick one version u want and with the song information that we have "Song Name" "Arists" "Album" "Length"
here is a exmaple command i have for the way my bot is set up can we just work on doing /find song and then the song name and it gives a embed w the song information rn
const { ApplicationCommandOptionType } = require('discord.js');
module.exports = { data: { name: 'Example Name', description: 'Example Desc', integration_types: [0, 1], contexts: [0, 1, 2], options: [ { name: 'Example Name', description: 'Example Desc', type: ApplicationCommandOptionType.User, required: false } ] },
async execute(interaction) { }};
Assistant
Here’s a minimal working version of
/find song <name>that:- searches your local
Songsfolder for files whose names contain the query (case-insensitive) - builds an embed with the first match’s metadata (title, artist, album, length)
- attaches the actual audio file so the user can download it
- (for now) only returns the first match – we’ll add the “multiple versions” dropdown in the next step once this part is solid.
Folder layout expected:
bot-root/ ├─ commands/ │ └─ find.js ← this file └─ Songs/ ├─ Juice WRLD - Baby (Demo).mp3 ├─ Juice WRLD - Baby (OG).mp3 └─ …Install the helper packages once:
npm i music-metadata
commands/find.jsconst { SlashCommandBuilder, EmbedBuilder, AttachmentBuilder } = require('discord.js'); const fs = require('fs'); const path = require('path'); const mm = require('music-metadata'); // Absolute path to your Songs folder const SONGS_DIR = path.join(__dirname, '..', 'Songs'); module.exports = { data: new SlashCommandBuilder() .setName('find') .setDescription('Search for an unreleased Juice WRLD song') .addStringOption(opt => opt.setName('song') .setDescription('Song name to search for') .setRequired(true) ), async execute(interaction) { await interaction.deferReply(); // we might do file uploads const query = interaction.options.getString('song', true).toLowerCase(); // Grab every file in Songs/ const files = fs.readdirSync(SONGS_DIR).filter(f => f.toLowerCase().includes(query)); if (files.length === 0) { return interaction.editReply({ content: '❌ No matches found.' }); } // For now just take the first match const fileName = files[0]; const filePath = path.join(SONGS_DIR, fileName); // Parse metadata let meta; try { meta = await mm.parseFile(filePath); } catch { meta = { format: {}, common: {} }; } const title = meta.common.title || path.parse(fileName).name; const artist = meta.common.artist || 'Unknown'; const album = meta.common.album || 'Unreleased'; const length = meta.format.duration ? `${Math.floor(meta.format.duration / 60)}:${String(Math.floor(meta.format.duration % 60)).padStart(2, '0')}` : '?'; const embed = new EmbedBuilder() .setTitle(title) .setDescription(`**Artist:** ${artist}\n**Album:** ${album}\n**Length:** ${length}`) .setColor(0x00ff00) .setFooter({ text: 'Unreleased archive' }); const attachment = new AttachmentBuilder(filePath, { name: fileName }); return interaction.editReply({ embeds: [embed], files: [attachment] }); } };
Test it:
- Drop the file above into
commands/find.js. - Restart / reload your bot.
- In Discord:
/find song: baby
You’ll get an embed with the metadata and the
.mp3attached for download.Next step (when you’re ready):
- If
files.length > 1, build aStringSelectMenuBuilderwith the list of matches, collect the interaction, then send the chosen file.
- searches your local
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.