Reputation: 38
So I have bot that responses random message from array. Now I want it to response text & image same time. I tried this:
let msgs = [{text:'Hi guys', pic: new Discord.MessageAttachment('https://i.ytimg.com/vi/JilHZ_DdBYg/maxresdefault.jpg')}, "xd", "hello", "hi my friend"]
let random = Math.floor(Math.random() * msgs.length);
let random_msg = msgs[random];
message.channel.send(random_msg)
the error is:
UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot send an empty message
Upvotes: 0
Views: 51
Reputation: 95
It appears that the DiscordAPI message sdk can only send non-empty strings. Rather than using Math.random() for your testing you should loop through your messages array and attempt to send each message, at which point you will discover that the zero index object will throw an error. You will need to further investigate the discord documentation to find how to send a captioned image.
Upvotes: 1