当机器人由服务器托管时发送嵌入消息时出错

Posted

技术标签:

【中文标题】当机器人由服务器托管时发送嵌入消息时出错【英文标题】:Error when sending a embed message when the bot is hosted by a server 【发布时间】:2020-08-05 21:40:33 【问题描述】:

(node:24) UnhandledPromiseRejectionWarning: TypeError: fields.flat is not a function

是否有人知道如何在服务器上托管机器人时解决此错误,因为当新用户加入 disord 服务器时会出现该错误,并且通常机器人会发送嵌入 dm 欢迎消息,但现在它只是给了我这个错误,当我在我的电脑上启动机器人时,它工作得很好,当我使用非嵌入版本时,它也可以在服务器上工作,所以它与嵌入消息有关。

顺便说一句,我的整个代码:

const Discord = require('discord.js');
const  prefix, token  = require('./config.json');
const client = new Discord.Client();

client.on('ready', () => 
    console.log('Ready!');
    client.user.setPresence( activity:  name: 'with servers!????' , status: 'online' )
)

client.on("guildMemberAdd", member => 
    try 
        const Embed = 
            color: 0x0099ff,
            title: 'Welcome!',
            url: 'https://potatohost.cc',
            description: 'We offer Budget Minecraft, Minecraft Bedrock, Rust, Deticated Servers, Discord Bot and VPS Servers. We also sell domains and web designs!',
            thumbnail: 
                "url": 'attachment://ironnode.png',
            ,
            fields: [
                
                    name: `Hey!`,
                    value: `I want to help you and so my question is: Do you want to buy a server or do you need more information first? \n
                    A: I want to buy a server
                    B: I need more information first \n
                    Please react to this message with A or B.`,
                ,
            ],
            image: 
                url: "attachment://ironnode.png",
            ,
            timestamp: new Date(),
            footer: 
                text: 'Have a great time!',
                icon_url: "attachment://ironnode.png",
            ,
        ;

        member.send( embed: Embed, files: [
            attachment:'/home/container/ironnode.png',
            name:'ironnode.png'
          ] )

        .then(function (message) 
            message.react("????")
            message.react("????")
            const filter = (reaction, user) => 
                return ['????', '????'].includes(reaction.emoji.name) && user.id === member.id;
        ;

        message.awaitReactions(filter,  max: 1 )
                .then(collected => 
                    const reaction = collected.first();

                    if (reaction.emoji.name === '????') 
                        const Embed = 
                            color: 0x0099ff,
                            description: 'Ok, so you want to buy a server. Let me recommend you to create a ticket in <#700601793750499348>.',
                        ;
                        message.channel.send( embed: Embed )
                    
                    else 
                        const Embed = 
                            color: 0x0099ff,
                            description: 'Ok, so you need more information first. Let me recommend you to visit <#700610172879634472>.',
                        ;
                        message.channel.send( embed: Embed )
                        
                )
        );
    catch (err) 
         console.log(err)
    
)

client.on('message', message => 
    if (message.content === `$prefixping`) 
        message.channel.send('Pong.');
    
);

client.login(token);

【问题讨论】:

【参考方案1】:

确保您的 NodeJS 版本高于 v12:https://nodejs.org/

【讨论】:

以上是关于当机器人由服务器托管时发送嵌入消息时出错的主要内容,如果未能解决你的问题,请参考以下文章

从我的浏览器连接到 Azure Service Fabric 集群中托管的服务时出错

如何发送 APNS PushSharp 发送通知。它在 asp.net 中的 localhost 工作,但是当我们在 Windows 服务器中托管 API 时失败

我想在机器人关闭或打开的某个频道中发送一条消息

错误:26 - 在托管到 Web 服务器后定位服务器/实例时出错

使用自托管 Azure Service Fabric 调用 Web API 时出错

Windows 服务可以使用由另一个 Windows 服务托管的 WCF 服务吗?