'Lavasfy client is not a constructor
I'm working on a music bot project, the error said LavasfyClient is not a constructor, the code was scrapped because I switch from erela.js-spotify to lavasfy, I don't know what I do wrong and I've read the documentation of lavasfy.
Some parts might be empty because I delete them (like clientID, lavalink host, password, etc)
Here's my code:
Manager
} = require("erela.js"),
LavasfyClient = require("lavasfy"),
Deezer = require("erela.js-deezer"),
Facebook = require("erela.js-facebook"),
config = require(`${process.cwd()}/botconfig/config.json`),
clientID = process.env.clientID || config.spotify.clientID,
clientSecret = process.env.clientSecret || config.spotify.clientSecret;
module.exports = (client) => {
if (!clientID || !clientSecret || clientID.length < 5 || clientSecret.length < 5) {
client.manager = new Manager({
plugins: [
new Deezer(),
new Facebook(),
],
send(id, payload) {
var guild = client.guilds.cache.get(id);
if (guild) guild.shard.send(payload);
},
});
} else {
client.manager = new Manager({
nodes: collect(config.clientsettings.nodes),
plugins: [
new LavasfyClient({
clientID: "",
clientSecret: "",
}),
],
send(id, payload) {
var guild = client.guilds.cache.get(id);
if (guild) guild.shard.send(payload);
},
});
}
//require the other events
require("./node_events")(client)
require("./client_events")(client)
require("./events")(client)
require("./musicsystem")(client)
};
function collect(node) {
return node.map(x => {
if (!x.host) throw new RangeError('"host" must be provided');
if (!x.password) throw new RangeError('"password" must be provided');
if (typeof x.port !== 'number') throw new RangeError('"port" must be a number');
if (x.retryAmount && typeof x.retryAmount !== 'number') throw new RangeError('Retry amount must be a number');
if (x.retryDelay && typeof x.retryDelay !== 'number') throw new RangeError('Retry delay must be a number');
if (x.secure && typeof x.secure !== 'boolean') throw new RangeError('Secure must be a boolean');
return {
host: x.host ? x.host : '',
password: x.password ? x.password : '',
port: x.port && !isNaN(x.port) ? Number(x.port) : 443,
identifier: x.identifier || x.host,
retryAmount: x.retryAmount ? Number(x.retryAmount) : 5,
retryDelay: x.retryDelay ? Number(x.retryDelay) : 5000,
secure: x.secure ? x.secure : false
};
});
}
Solution 1:[1]
LavasfyClient is not a default export. You need to destructure it like this:
const { LavasfyClient } = require("lavasfy");
// ...
// ...
// ...
plugins: [
new LavasfyClient({
clientID: "",
clientSecret: "",
}),
],
Solution 2:[2]
I changed the process to actually modify the following file instead of sending the system commands.
/etc/network/interfaces.d/eth0
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Zsolt Meszaros |
| Solution 2 | Kevin Lay |
