Reputation:
I am trying to call the constant musicSettings stored in my ready.js file however, cannot seem to export it. In my ready.js file (this needs to be in there as this is one of the only places I can access this.client)
const { Listener } = require('discord-akairo');
const { Client: Lavaqueue } = require('lavaqueue');
const { ClientID } = require('../config');
class ReadyListener extends Listener {
constructor() {
super('ready', {
emitter: 'client',
eventName: 'ready'
});
}
exec() {
process.stdout.write(`[>] Running in ${this.client.guilds.size} servers.\n`);
}
}
const musicSettings = new Lavaqueue({
userID: ClientID,
password: 'g6Z0xRLbiTHq',
hosts: {
rest: 'http://127.0.0.1:2333',
ws: 'ws://127.0.0.1:2333',
redis: { host: 'localhost' },
},
send(guildID, packet) {
this.client.ws.send(packet)
},
});
module.exports = ReadyListener;
Code located in the play.js file (does not work because I cannot import musicSettings from the ready.js file)
async exec(message, args) {
var channel = message.member.voiceChannel;
if (!channel) {
return message.reply('you need to be in a voice channel to play music.')
} else if (!args.video) {
return message.reply('you need to provide a link or search for a video.')
}
const song = await musicSettings.load(args.video);
const queue = musicSettings.queues.get(`${message.guild.id}`);
await queue.player.join(`${message.member.voiceChannel.id}`);
await queue.add(...song.tracks.map(s => s.track));
await queue.start();
}
}
Upvotes: 2
Views: 332
Reputation: 370699
Export the musicSettings
instance from ready.js
:
module.exports = { ReadyListener, musicSettings };
And then import it in play.js
:
const { musicSettings } = require('./ready');
And then you'll be able to reference musicSettings
in play.js
.
Note that since ready.js
is now exporting two things, to import ReadyListener
, you'll have to use the same sort of syntax as used to import musicSettings
, eg:
const { ReadyListener } = require('./ready');
Or, if you want to import both at once:
const { ReadyListener, musicSettings } = require('./ready');
Upvotes: 1