简体   繁体   English

找出表情符号是否可以在 Discord.JS 中使用?

[英]Find out if an emoji is usable in Discord.JS?

As you can see in this image , the bottom half of those Discord emojis in my server are grayed out.正如您在这张图片中看到的,我服务器中那些 Discord 表情符号的下半部分是灰色的。 This is because I used to have two Server Boosts, but for now I don't .这是因为我曾经有两个 Server Boosts,但现在我没有 I'm making an emoji picker for my Discord.JS Bot which needs to be able to detect every available emoji.我正在为我的 Discord.JS Bot 制作一个表情符号选择器,它需要能够检测到每个可用的表情符号。 Unfortunately, I don't know how to get my bot to detect if the emoji is usable.不幸的是,我不知道如何让我的机器人检测表情符号是否可用。 I also couldn't find anything useful here: https://discord.js.org/#/docs/main/stable/class/Emoji .我在这里也找不到任何有用的东西: https : //discord.js.org/#/docs/main/stable/class/Emoji My current code:我目前的代码:

let emojiurls = [];
await client.emojis.array().forEach((item, index)=>{
    emojiurls.push({"name":item.name,"url":item.url});
});
return res.json(emojiurls);

I probably need to use something like client.emojis.available.array() or something but that doesn't seem to work.我可能需要使用诸如client.emojis.available.array()东西,但这似乎不起作用。

In the next Version of Discord.js ( v11.5 ) there will be a .available .在 Discord.js (v11.5) 的下一个版本中,将会有一个.available

You can upgrade by running npm i discordjs/discord.js#11.5-dev .您可以通过运行npm i discordjs/discord.js#11.5-dev进行升级。 This version upgrade should come with no breaking changes unless you are using deprecated features.除非您使用已弃用的功能,否则此版本升级不应带来重大更改。

With this new property you should be able to do:有了这个新属性,您应该能够:

let emojiurls = [];
client.emojis.filter(emoji => emoji.available).forEach(emoji => { emojiurls.push({ "name": emoji.name, "url": emoji.url }); });
return res.json(emojiurls);

This can be shortend down to:这可以缩短为:

const emojiurls = client.emojis
    .filter(emoji => emoji.available)
    .map(emoji => { 
        return { "name": emoji.name, "url": emoji.url };
     });
return res.json(emojiurls); 

Additionally, due to discord.js not changing the Version String in the Dev Branch, it will still sho 11.5.1.此外,由于 discord.js 没有更改 Dev Branch 中的版本字符串,它仍然会显示 11.5.1。

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

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