简体   繁体   English

如何将自定义表情符号转换为数组?

[英]How can I convert custom emojis to an array?

I'm trying to convert all emojis in a message to an array.我正在尝试将消息中的所有表情符号转换为数组。 I've tried this:我试过这个:

const myArray = message.attachments.array();

and this:还有这个:

const myArray = Array.from(message.attachments);

but they both return: []但他们都返回: []

You could check if the message contains emojis with regular expression (regex).您可以检查消息是否包含带有正则表达式 (regex) 的表情符号。 For example:例如:

let array = [],
    rgx = /(:)/g, // This will check for the emoji syntax e.g. :mali_borivoje:
    item;

while(item = rgx.exec()) {
    array.push(item[1]);
    array.join(' ');
}

Note: This code is purely for showcase purpose, it may not work out of the box for you.注意:此代码纯粹用于展示目的,它可能不适合您开箱即用。 You may update it accordingly to your code base and intentions.您可以根据您的代码库和意图对其进行相应更新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM