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

261
Visualizações
discord.js bot random images

I want to create a bot that picks a random image from an array of links, but I don't know what's wrong with it, here's the code and error

const arg = message.content.slice(prefix.lenght).split(/ +/);
const command = arg.shift().toLowerCase();

if(command === 'jtoh'){
  
  const rando_imgs = [
    'https://media.giphy.com/media/CZpro4AZHs436/giphy.gif',
    'https://media.giphy.com/media/CZpro4AZHs436/giphy2.gif',
    'https://media.giphy.com/media/CZpro4AZHs436/giphy3.gif',
    ]
    message.channel.send( {
      file: rando_imgs[Math.floor(Math.random() * rando_imgs.length)]
  });
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The error is that the send() method accepts an object with a files property (not file). This should be an array where you can add your random image. The following will work for you:

if (command === 'jtoh') {
  const rando_imgs = [
    'https://media.giphy.com/media/CZpro4AZHs436/giphy.gif',
    'https://media.giphy.com/media/CZpro4AZHs436/giphy2.gif',
    'https://media.giphy.com/media/CZpro4AZHs436/giphy3.gif',
  ];
  message.channel.send({
    files: [rando_imgs[Math.floor(Math.random() * rando_imgs.length)]],
  });
}

If you want to display the message, you could just use the content property instead. In this case, you don't have to send an array.

message.channel.send({
  content: rando_imgs[Math.floor(Math.random() * rando_imgs.length)],
});

Also, there is a typo; prefix.lenght should be prefix.length.

const arg = message.content.slice(prefix.length).split(/ +/);
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