【问题标题】:Connection .Then is not a functionConnection .Then 不是函数
【发布时间】:2020-11-12 14:59:03
【问题描述】:

当我尝试为 discord bot 创建 StateManager.js 文件时出现错误,当我尝试启动 discord bot 时出现错误 .then((connection) => this.connection = 连接) ^ TypeError: connection.then 不是函数,有什么解决办法吗?该连接是使用单独的文件连接到一个不和谐机器人的数据库,而不是在 index.js 文件中。

const { EventEmitter } = require('events');
const connection = require('../../database/db');

class StateManager extends EventEmitter{
    constructor (opts){
        super(opts);
        connection
        .then((connection) => this.connection = connection)
            .catch(err => console.log(err));
        



    }
}

module.exports = new StateManager();

【问题讨论】:

    标签: javascript discord discord.js


    【解决方案1】:

    假设“connection”应该返回一个promise,您首先必须调用connection方法才能访问promise。

    class StateManager extends EventEmitter{
        constructor (opts){
            super(opts);
            connection()
            .then((connection) => this.connection = connection)
                .catch(err => console.log(err));
    
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-14
      • 2019-02-10
      • 1970-01-01
      • 1970-01-01
      • 2017-10-07
      • 2021-07-24
      • 2020-09-06
      • 1970-01-01
      相关资源
      最近更新 更多