Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

296
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda