Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

286
Vistas
Discord.js | How do I make my bot send a random image?

I have tried a bunch of things that I've seen and none of them seem to be working for me. I am using the thing where when you do a command it activates a file in the commands folder, and most of the other scripts dont use that.

1

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Without seeing any code, it is quite difficult to point you in the right direction. It would help more to define the issue you are having (actual errors and/or functionality) along with seeing the code you are using. The solution also depends on where the images are coming from.

Assuming your images are in a local folder, here is a basic example:

if (message.content === '!random') {
    // get a random index between 0 and length
    const idx = (len) => Math.floor(Math.random() * (len));

    // get all the files in the directory
    const files = fs.readdirSync('/images/');

    // get file from directory
    const myImage = files[idx(files.length)];
    
    // send image to channel
    message.channel.send({ files: [`/images/${myImage}`] });
}

Assuming images are from https://picsum.photos/, here is an basic example:

if (message.content === '!random') {
    const seed = Math.floor(Math.random() * 1000);
    const h = Math.floor(Math.random() * 400) + 100;
    const w = Math.floor(Math.random() * 400) + 100;
    
    // create embed with random image
    const embed = new MessageEmbed().setImage(`https://picsum.photos/seed/${seed}/${h}/${w}`);
    
    // send embed
    message.channel.send({ embeds: [embed] });

    // delete command
    message.delete();
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda