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

255
Views
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 answers
Answer question

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 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!