[英]How can I pass text & image to array
所以我有机器人响应来自数组的随机消息。 现在我希望它同时响应文本和图像。 我试过这个:
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)
错误是:
UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot send an empty message
看来 DiscordAPI 消息 sdk 只能发送非空字符串。 与其使用 Math.random() 进行测试,不如循环遍历消息数组并尝试发送每条消息,此时您会发现零索引对象将引发错误。 您将需要进一步调查不和谐文档以了解如何发送带标题的图像。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.