So basically I'm trying to create a Discord bot that when you type "!cat" the Discord bot sends an image of a random cat inside of an embed but every time I use the command the image stays the same.... I tried to put the embed variable inside of the function so it refreshes every time someone says "!cat" but it didn't work..... this is the code that I'm using:
const Discord = require('discord.js'); const client = new Discord.Client(); client.once('ready', () => { console.log('Ready!'); }); client.on('message', message => { console.log(message.content); if (message.content === "!cat") { const catEmbed = new Discord.MessageEmbed() .setTitle("MEOW!") .setImage("http://theoldreader.com/kittens/600/400") .setThumbnail("http://theoldreader.com/kittens/600/400") message.channel.send(catEmbed) } }); client.login('NOT GONNA TELL MY TOKEN');
It looks like a caching issue. Try to append some random character as a query string to your URL. Something like this should work:
client.on('message', (message) => {
if (message.content === '!cat') {
// generate a random string
const rand = Math.random().toString(36).slice(2);
const catEmbed = new Discord.MessageEmbed()
.setTitle('MEOW!')
// append it as a query string
.setImage(`http://theoldreader.com/kittens/600/400?${rand}`)
.setThumbnail(`http://theoldreader.com/kittens/600/400?${rand}`);
message.channel.send(catEmbed);
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.