Reputation: 11
I have a command for my DiscordJS bot that has an array of Imgur links. I want it to select a single link randomly and embed that in a message to the channel. I think I am close. How do I call it from the array?
if (command == "dude") return dude(args, message);
function dude(args, message) {
if (args.length > 0)
return message.channel.send(You are not using this command correctly.);
const embed = new Discord.RichEmbed();
var dudes = ["imgururl1", "imgururl2", "imgururl3", "imgururl4" ];
var dude = Math.floor(Math.random() * dudes.length);
embed.setImage([dude]);
message.channel.send(embed);
};
Upvotes: 1
Views: 913
Reputation: 85
It looks good, just make sure, as Kaynn said, to call the dude
variable from the dudes
array:
dudes[dude];
Or, you can define dude with it altogether:
var dude = dudes[Math.floor(Math.random() * dudes.length)];
Also, make sure to send the message within double quotes to make it a string, otherwise, the system is going to give a syntax error.
Upvotes: 0
Reputation: 4056
You just needed to access the array with the given index.
embed.setImage(dudes[dude]);
Upvotes: 3