Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

270
Views
La inserción en mi comando de búsqueda no funciona correctamente

En este comando de search , el bucle for in no agrega los campos a la inserción. Cuando uso el comando, obtengo el nombre y la descripción, que definí al crear la inserción. Pero no obtengo los campos que agrego en el bucle for in .

Aquí hay una imagen de lo que se devuelve, en caso de que ayude a responder mi pregunta:

Una imagen de lo que devuelve el comando.

Mi código de comando de search :

 const { MessageEmbed } = require('discord.js') module.exports = { name: 'search', description: 'Searches for a song and returns the results.', options: [ { name: 'search_term', description: 'The song to search for.', type: 'STRING', required: true }, { name: 'limit', type: 'INTEGER', description: 'Number of results to return.', required: true }, { name: 'type', type: 'STRING', description: 'The type of search result.', required: true, choices: [{ name: 'Video', value: 'video' }, { name: 'Playlist', value: 'playlist' }] } ], async execute(interaction) { const query = await interaction.options.getString('search_term') const limit = await interaction.options.getInteger('limit') const type = await interaction.options.getString('type') let type2 = 'x' if (type === 'video') type2 = 'Video' else if (type === 'playlist') type2 = 'Playlist' let results = await interaction.client.distube.search(query, { limit: limit, type: type }) let embed = new MessageEmbed() .setTitle('search') .setDescription('Searches for a song and returns the results.') for (const result in results) { if (result.type === 'video') { embed.addFields({ name :result.name, value: `ID: ${result.id}\nType: ${type2}\nURL: ${result.url}\nViews: ${result.views}\nDuration: ${result.formattedDuration}\nLive: ${result.isLive}`, inline: true}) } else if (result.type === 'playlist') { embed.addFields({ name: result.name, value: `ID: ${result.id}\nType: ${type2}\nURL: ${result.url}\nViews: ${result.views}`, inline: true}) } } await interaction.reply({embeds: [embed]}) }, };
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Debe usar embed.addField(...) o pasar una matriz a embed.addFields([...]) .

<MessageEmbed>.addFields() toma una matriz como entrada.

about 4 years ago · Juan Pablo Isaza Report

0

La solución: Usar for of en lugar de for in

Diferencia entre los 2:

La instrucción for...of crea un bucle que itera sobre objetos iterables , incluidos: String , Array , objetos similares a matrices (p. ej., argumentos o NodeList ), TypedArray , Map , Set

La instrucción for...in itera sobre todas las propiedades enumerables de un objeto que están tecleadas por cadenas (ignorando las tecleadas por símbolos), incluidas las propiedades enumerables heredadas.

Para más información:

for of : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of

for in : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!