DiscordJS:导出客户端返回未定义

时间:2020-10-14 01:10:30

标签: node.js discord.js

由于某种原因导出时,对象客户端未定义。对文件的所有引用均正确。在other.js中登录客户端返回未定义。

index.js

const Discord = require("discord.js");
const client = new Discord.Client();
const lobby = require('./other.js');
const lobby1 = lobby.lobby(whateverID);

client.on("message", function(message) {
    //...
    lobby1.ret();

});
client.login(process.env.TOKEN);
module.exports.client = client;

other.js

const Discord = require("discord.js");
const client = require('./index.js').client;
class Lobby {
    constructor(ChannelID) {
        //...
    }

    ret() {
        client.channels.cache.get(ChannelID).send("return");
    }
}
module.exports.lobby = Lobby;

错误消息:

client.channels.cache.get(ChannelID).send("return");
TypeError: Cannot read property 'channels' of undefined

密切相关:Discord client object is undefined after being exported

0 个答案:

没有答案
相关问题