mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 00:23:30 +01:00
add the functions to voice connection
This commit is contained in:
@@ -4,6 +4,7 @@ const VoiceReceiver = require('./receiver/VoiceReceiver');
|
||||
const Constants = require('../../util/Constants');
|
||||
const AudioPlayer = require('./player/AudioPlayer');
|
||||
const EventEmitter = require('events').EventEmitter;
|
||||
const fs = require('fs');
|
||||
|
||||
/**
|
||||
* Represents a connection to a Voice Channel in Discord.
|
||||
@@ -41,7 +42,7 @@ class VoiceConnection extends EventEmitter {
|
||||
|
||||
this.player.on('error', e => {
|
||||
this.emit('warn', e);
|
||||
console.log('so yeah uh'+e);
|
||||
console.log('so yeah uh' + e);
|
||||
this.player.cleanup();
|
||||
});
|
||||
|
||||
@@ -92,6 +93,18 @@ class VoiceConnection extends EventEmitter {
|
||||
});
|
||||
}
|
||||
|
||||
playFile(file) {
|
||||
return this.playStream(fs.createReadStream(file));
|
||||
}
|
||||
|
||||
playStream(stream) {
|
||||
return this.player.playUnknownStream(stream);
|
||||
}
|
||||
|
||||
playConvertedStream(stream) {
|
||||
return this.player.playPCMStream(stream);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = VoiceConnection;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
const ConverterEngine = require('./ConverterEngine');
|
||||
const ChildProcess = require('child_process');
|
||||
const EventEmitter = require('events').EventEmitter;
|
||||
require('longjohn');
|
||||
|
||||
class PCMConversionProcess extends EventEmitter {
|
||||
|
||||
|
||||
@@ -161,7 +161,7 @@ let disp, con;
|
||||
client.on('message', msg => {
|
||||
if (msg.content.startsWith('/play')) {
|
||||
const chan = msg.content.split(' ').slice(1).join(' ');
|
||||
con.player.playUnknownStream(ytdl(chan, {filter : 'audioonly'}), { passes : 4 });
|
||||
con.playStream(ytdl(chan, {filter : 'audioonly'}), { passes : 4 });
|
||||
}
|
||||
if (msg.content.startsWith('/join')) {
|
||||
const chan = msg.content.split(' ').slice(1).join(' ');
|
||||
@@ -169,7 +169,7 @@ client.on('message', msg => {
|
||||
.then(conn => {
|
||||
con = conn;
|
||||
msg.reply('done');
|
||||
disp = conn.player.playUnknownStream(ytdl(song, {filter:'audioonly'}), { passes : 3 });
|
||||
disp = conn.playStream(ytdl(song, {filter:'audioonly'}), { passes : 3 });
|
||||
conn.player.on('debug', console.log);
|
||||
conn.player.on('error', err => console.log(123, err));
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user