You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Eris机器人读取UnbelievaBoat消息嵌入(Embed)功能异常求助

Eris机器人读取UnbelievaBoat消息嵌入(Embed)功能异常求助

我最近在折腾用JavaScript写的Eris机器人,想实现读取UnbelievaBoat发送的消息嵌入功能,但实际跑起来完全没达到预期效果。已经耗了好长时间在这上面了,真不想就这么把这段代码扔了,有没有大佬能帮忙看看问题出在哪?要是实在没办法也麻烦告诉我一声,至少让我死个明白😂

先给大家看看运行日志:

Received message: <@1204873782519398520> test from toxiclikeme1599 (ID: 1015941241533366366) in channel 1325089634946125868
Received message: .dep 1015941241533366366 1000 from EHFB | Finance Bank Bot (ID: 1204873782519398520) in channel 1325089634946125868
Detected .dep command
User mention: 1015941241533366366, Amount: 1000
Waiting for .pay message...
Received message: .pay <@1325065822636609578> 1000 from toxiclikeme1599 (ID: 1015941241533366366) in channel 1197500600791863346
Filter check - Channel: true, Command: true, Mention: false
Received message: from UnbelievaBoat (ID: 292953664492929025) in channel 1197500600791863346
Filter check - Channel: true, Command: false, Mention: false

然后是我的代码:

bot.on('messageCreate', async (msg) => {
    console.log(
        `Received message: ${msg.content} from ${msg.author.username} (ID: ${msg.author.id}) in channel ${msg.channel.id}`
    );

    if (
        msg.channel.id === BOT_CHANNEL_ID &&
        msg.content.startsWith('.dep ') &&
        msg.author.id === '1204873782519398520'
    ) {
        console.log('Detected .dep command');
        const args = msg.content.split(' ');

        if (args.length !== 3 || isNaN(args[2])) {
            bot.createMessage(msg.channel.id, 'Invalid command format. Usage: `.dep <@user> <amount>`');
            return;
        }

        const userMention = args[1];
        const userID = userMention.replace(/[<@!>]/g, ''); // Extract user ID from mention
        const amount = args[2];
        console.log(`User mention: ${userMention}, Amount: ${amount}`);

        const filterPay = (m) => {
            const isCorrectChannel = m.channel.id === PAY_CHANNEL_ID;
            const isPayCommand = m.content.startsWith('.pay');
            const includesUserMention =
            m.content.includes(`<@${userID}>`) || m.content.includes(`<@!${userID}>`);

            console.log(
                `Filter check - Channel: ${isCorrectChannel}, Command: ${isPayCommand}, Mention: ${includesUserMention}`
            );
            return isCorrectChannel && isPayCommand && includesUserMention;
        };

        console.log('Waiting for .pay message...');
        const payMessage = await waitForMessage(filterPay, 600000);
        if (!payMessage) {
            bot.createMessage(msg.channel.id, 'No `.pay` message received within the time limit.');
            return;
        }
        console.log('Received .pay message:', payMessage.content);

        const filterResponse = (m) => {
            const hasEmbed = m.embeds && m.embeds.length > 0;
            if (!hasEmbed) return false;

            const embed = m.embeds[0];
            const descriptionMatches =
            embed.description.includes(`<@${userID}>`) || embed.description.includes(`<@!${userID}>`);
            const authorMatches = embed.author && embed.author.name === payMessage.author.username;

            console.log(
                `Response filter check - Has Embed: ${hasEmbed}, Description Matches: ${descriptionMatches}, Author Matches: ${authorMatches}`
            );
            return descriptionMatches && authorMatches;
        };

        console.log('Waiting for response embed from UnbelievaBoat...');
        const responseMessage = await waitForMessage(filterResponse, 600000);
        if (!responseMessage) {
            bot.createMessage(msg.channel.id, 'No response embed received within the time limit.');
            return;
        }
        console.log('Received response embed:', responseMessage.embeds[0].description);
    }
});

async function waitForMessage(filter, time) {
    return new Promise((resolve) => {
        const timeout = setTimeout(() => resolve(null), time);

        const listener = (message) => {
            if (filter(message)) {
                clearTimeout(timeout);
                bot.off('messageCreate', listener);
                resolve(message);
            }
        };
        bot.on('messageCreate', listener);
    });
}

从日志里能看到UnbelievaBoat确实发了消息,但我的过滤器完全没触发针对嵌入的检查逻辑——日志里根本没打出Response filter check相关的内容,是不是我写的filterResponse哪里有问题?或者是UnbelievaBoat的消息结构和我想的不一样?

备注:内容来源于stack exchange,提问作者Hauscrafter1978

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 12:48:00