[英]discord.js random images displaying incorrectly
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. 我想也许是因为它一遍又一遍地从同一个随机的img url抓住它们,但我不知道如何改变它。 thank you and I hope someone will be able to help.
谢谢,我希望有人能够提供帮助。
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(),
},
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.
我发现这是随机unsplash链接的正确格式。
image: {
url: "https://source.unsplash.com/random?sig=" + Math.random(),
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.