2
votes

I want to grab random images from the url, but when I call the command in discord, it supplies the same image over and over. But when I restart the bot and run it again, the image changes but still plays that different images over and over again without any variety? I would highly appreciate any help

else if (message.content.startsWith(prefix + "randimg") && message.author != client.user) {
  message.channel.send({embed: {
      color: 0x0000FF,
      author: {
          name: client.user.username,
          icon_url: client.user.avatarURL
      },
      title: "Random Image Test",
      image: {
          url: "https://source.unsplash.com/random",
      },
      description: "Random Image Generation"
  },
  currentTimestamp: new Date(),
  footer: {
    icon_url: client.user.avatarURL,
    text: "2018 @ Canarado"
  }
})

I thought perhaps it is the fact that its grabbing them from the same random img url over and over, but I wouldnt know how to go about changing that. thank you and I hope someone will be able to help.

2
Nothing is wrong with your syntax. Maybe there is a different way to use the unsplash url.user7896971
Yeah, I just don't know. Is there some javascript method that changes the url every, x amount of seconds to a new random unsplash url? @FrostAdam Kerik
If you declare all the contents of that message.channel.send call in a variable before does that help possibly (and pass in the variable in the call)?chackerian
That didnt work unfortunately @chackerianAdam Kerik
Maybe this type of thing might help you, not sure. It finds the redirect url of a link. redirectdetective.com and here is the code: redirectdetective.com/ajax.jschackerian

2 Answers

1
votes

Is it possible that caching be root cause? Do you try add a random parameter to your url?

image: {
      url: "https://source.unsplash.com/random" + "?rnd=" + Math.random(),
  },
0
votes

So after meticulous research, the problem was indeed caching, but the other available answer (tho it was good and helped me think) didn't format the link correctly. I found this to be the correct format for a random unsplash link.

          image: {
          url: "https://source.unsplash.com/random?sig=" + Math.random(),
      },