从 Discord 获取原始表情符号时出现问题 [discord.js/discordjs v14]

问题描述 投票:0回答:1

我正在尝试创建一个不和谐的机器人,根据对机器人消息的反应来分配角色。 我可以使用自定义表情符号执行操作,如下所示:

const GET_EMOJI = (name) => client.emojis.cache.find(emoji => emoji.name === name);

但不适用于原始表情符号。

index.js:

const { Client, GatewayIntentBits} = require("discord.js");
const { TOKEN } = require("./config.json");
const ROLE_CLAMED = require("./utils/roleClaimed");

const BOT = new Client({
    intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages] 
});

BOT.once("ready", () => {
    console.log("Hello I'm ready !!!");
    ROLE_CLAMED(BOT);
});

BOT.login(TOKEN);

roleClaimed.js

const { Client } = require("discord.js");
const FIRST_MSG = require("./firstMsg");

const ROLE_CHANEL_NAME = "roles";

const EMOJIS = {
    // custom emojis
    valorant: "0valo",
    // destiny2: "0dest",
    // LeagueOfLegends: "0lol",
    // original emojis
    test_1: "milky_way",
    // test_2: ":gun:",
    // test_3: ":milky_way:",
}

module.exports = (client) => {
    const CHANNEL = client.channels.cache.find(e => e.name === ROLE_CHANEL_NAME);
    const GET_EMOJI = (name) => client.emojis.cache.find(e => e.name === name);
    const CHOICE = [];
    let txt = "test msg\n\n";

    for (const KEY in EMOJIS) {
        const ROLE = KEY;
        const EMOJI= GET_EMOJI(EMOJIS[KEY]);

        CHOICE.push(EMOJI);
        txt += `${EMOJI} : ${ROLE}\n`;
    }
    FIRST_MSG(CHANNEL, txt, CHOICE)
}

所以我有

<:emoji_name:emoji_ID>
用于自定义表情符号,但
undefined
用于不和谐表情符号。

你能帮我解决我的问题吗? 预先感谢。

reactjs discord discord.js bots
1个回答
0
投票

我相信

client.emojis.cache
不包含默认表情符号 - 默认表情符号只是 unicode 表情符号。当我尝试使用
client.emojis.cache.forEach(e => console.log(e))
打印缓存的表情符号时,只会给出
GuildEmoji
s,而
GuildEmoji
仅适用于根据 discord.js 文档的自定义表情符号。

您可以在

EMOJIS
中定义 unicode 表情符号吗,然后如果
EMOJIS[KEY]
未定义,则在示例代码中推送
EMOJI
吗?

const EMOJIS = {
    // custom emojis
    valorant: "0valo",
    // rest of your emojis here...
    // unicode emojis
    heart: '❤'
}

module.exports = (client) => {
    const CHANNEL = client.channels.cache.find(e => e.name === ROLE_CHANEL_NAME);
    const GET_EMOJI = (name) => client.emojis.cache.find(e => e.name === name);
    const CHOICE = [];
    let txt = "test msg\n\n";

    for (const KEY in EMOJIS) {
        const ROLE = KEY;
        const EMOJI = GET_EMOJI(EMOJIS[KEY]);
        if (!EMOJI) {
            CHOICE.push(EMOJIS[KEY])
        } else {
            CHOICE.push(EMOJI);
        }
        txt += `${EMOJI} : ${ROLE}\n`;
    }
    FIRST_MSG(CHANNEL, txt, CHOICE)
}

不确定您在其他地方的代码是否依赖于

GuildEmoji
类型。

祝你的机器人好运!

© www.soinside.com 2019 - 2024. All rights reserved.