【发布时间】:2021-01-09 23:40:56
【问题描述】:
我的主要目标是能够运行一个小命令,例如$yoink,它将获取聊天中最后发送的表情符号并将其制作成我可以下载的图像。我已经有了类似 的东西,但是它只检测常规图像和嵌入图像(使用它来让我的机器人使用 Jimp 功能)
这是我目前所拥有的:
async function GetImageFromMsg(msg) {
var imageUrl = null;
const urlsnifferpattern = /(https?:\/\/[^\s]+\.(?:png|jpg|jpeg|bmp|gif|tiff|webp)(?:$|[^\s]+))/i;
if (msg.attachments && (getImg = msg.attachments.find(val => val.height && val.url)) && getImg.url.match(urlsnifferpattern)) // user uploads directly to chat.
imageUrl = getImg.url;
if (msg.content && (getImg = msg.content.match(urlsnifferpattern))) // Here first to avoid caching issues on the next two checks.
imageUrl = getImg[0].replace(">", "");
if (msg.embeds && (getImg = msg.embeds.find(val => val.thumbnail && val.thumbnail.url))) // small image ONLY on bot-made embeds - (small??>)big image on LINK-made embeds - random image URLS with no embeds.
imageUrl = getImg.thumbnail.url;
if (msg.embeds && (getImg = msg.embeds.find(val => val.image && val.image.url))) // big image on bot-made embeds.
imageUrl = getImg.image.url;
if (!imageUrl)
return null;
return imageUrl;
}
我应该如何添加支持来抓取表情符号?
【问题讨论】:
标签: javascript node.js discord discord.js