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

211
Views
Cómo elegir una imagen aleatoria del directorio (Usando Repl.it)

Estoy haciendo una máquina de plátanos y toma una imagen de plátano al azar en un directorio que creé dentro del directorio divertido aquí está mi código:

 var fs = require('fs'); fs.readdir('./fun/bananas/', (err, files) => { if (err) console.log(err); let bonannapics = files.filter(f => f.split('.').pop() === 'png'); let chosenFile = bonannapics[Math.floor(Math.random() * bonannapics.length)] const attachment = new MessageAttachment(chosenFile) let bananaembed = new MessageEmbed() .setTitle("Bonana Machine") .setColor(config.color) .setDescription("here is your banana!") .attachFiles(attachment) .setImage(attachment) .setFooter(config.footer) message.channel.send(bananaembed); });

Aquí está el error:

 (node:6072) UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, stat '/home/runner/Gloozzys-Treehouse/banana3.png'

aquí está la estructura de carpetas: imagen de estructura de carpetas

cree que la imagen está en un directorio diferente, pero no sé por qué, si alguien pudiera ayudarme a resolver esto, sería genial.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Esta línea devuelve la lista de archivos en la carpeta ./fun/bananas/

 fs.readdir('./fun/bananas/', (err, files) => {

Al leer el archivo de esa carpeta, debe agregar la ruta de la carpeta al MessageAttahment

 const attachment = new MessageAttachment(chosenFile)

Conviértete en esto.

 const attachment = new MessageAttachment('./fun/bananas/' + chosenFile)
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!