-
Notifications
You must be signed in to change notification settings - Fork 153
Stopping Audio Playback #181
Comments
What's your code for doing this? |
|
I'm not sure PR #186 fixes this issue. It sounds like he's not keeping the stream open, but he hasn't posted his code, so I can't proceed until then. |
I'm having a similar issue of trying to stop. #186 doesn't fix it. When the bot leaves the channel or stops the stream while an audio file is playing, I get that same error. I'm not sure how to go about safely stopping the file stream before exiting the voice channel.
|
Your issue is just because you're leaving the channel without |
I've tried both leaving the channel and only stopping the stream without leaving the channel via |
What do you mean the socket gets closed? |
I mean that the socket is closed when I stop the stream, resulting in a crash. I get a similar error to rGunti
|
What's your code? I'm heading to sleep, I'll check in the morning. |
I've redacted the userIDs and voice channel id, but aside from that this is the same code that crashes when I stop the stream. var Discord = require('discord.io');
var bot = new Discord.Client({
autorun: true,
token: ""
});
var filePath = "";
var fs = require("fs"), path = require('path'), util = require('util');
var firstrun = true;
var currentlyPlaying;
var danZoneStarterIDs = ["", "", "", ""];
var danZoneTime = false;
var danZoneTimeRunning = false;
var danZoneSongChoice = 0;
var VCID = '';
bot.on('ready', function (event) {
console.log('Logged in as %s - %s\n', bot.username, bot.id);
if (firstrun) {
filePath = __dirname + "/";
firstrun = false;
}
});
// Automatically reconnect if the bot disconnects due to inactivity
bot.on('disconnect', function (erMsg, code) {
console.log(bot.userName + ' disconnected from Discord with code ' + code + ' for reason: ' + erMsg);
bot.connect();
});
bot.on('message', function (user, userID, channelID, text, event) {
if (userID != bot.id) {
if (danZoneStarterIDs.indexOf(userID) > -1) {
if (!danZoneTime && text.toLowerCase() == "!join") {
danZoneTime = true;
var files = fs.readdirSync(filePath + "Dan Zone Music");
danZoneSongChoice = Math.floor(Math.random() * files.length);
bot.sendMessage({ to: channelID, message: "Joining Channel" });
bot.joinVoiceChannel(VCID, function (error, events) {
//Check to see if any errors happen while joining.
if (error) return console.error(error);
});
}
else if (!danZoneTimeRunning && danZoneTime && text.toLowerCase().indexOf("!start") == 0) {
danZoneTimeRunning = true;
//Then get the audio context
bot.getAudioContext(VCID, function (error, stream) {
//Once again, check to see if any errors exist
if (error) return console.error(error);
bot.sendMessage({ to: channelID, message: "Now Playing: \"" + fs.readdirSync(filePath + "Dan Zone Music")[danZoneSongChoice].split('.')[0] + "\"" });
currentlyPlaying = fs.createReadStream(filePath + "Dan Zone Music/" + fs.readdirSync(filePath + "Dan Zone Music")[danZoneSongChoice])
//Without {end: false}, it would close up the stream, so make sure to include that.
currentlyPlaying.pipe(stream, { end: false });
if (error) return console.error(error);
//The stream fires `done` when it's got nothing else to send to Discord.
stream.on('done', function () {
if (danZoneTime) {
bot.leaveVoiceChannel(VCID);
danZoneTimeRunning = false;
danZoneTime = false;
bot.sendMessage({ to: channelID, message: "Finished Playing" });
}
//Handle
});
if (error) return console.error(error);
});
}
else if (danZoneTimeRunning && text.toLowerCase() == "!stop") {
danZoneTime = false;
danZoneTimeRunning = false;
bot.getAudioContext(VCID, function (err, stream) {
stream.stop();
}); //causes crash if stream is playing something
bot.sendMessage({ to: channelID, message: "Stopped" });
}
else if (text.toLowerCase() == "!leave") {
bot.leaveVoiceChannel(VCID);
}
}
}
}); |
Try making the |
Still no luck, same error. when creating a currentlyPlaying.unpipe(currentStream);
setTimeout(function () {
currentStream.stop();
}, 2000); I've tried without the setTimeout, setting currentStream to null afterward, not unpiping the filestream, all results in the same crash. |
Alright, that's weird, I'll check it out later on today when I have the time, but I wish Node error's weren't so generic at times. Sounds like it's a clear issue in the back-end due to some change on Discord's side, but I'm not sure where. |
Have you tried adding an error handler to the stream? ...
bot.getAudioContext(VCID, function (error, stream) {
//Once again, check to see if any errors exist
if (error) return console.error(error);
stream.on('error',function(err){console.log("AudioContext Error:",err)});
... |
I know i have when i was using it. Didn't get any error from it though | Didn't stop it from crashing. Socket closed error anyways. Only happened when the bot left. |
Still no update on this ? |
Any update on this? |
@rGunti i solve by like this : i create a start.js https://github.com/DeliDoktoru/FenomenDiscordBot/blob/master/start.js this js is a parent process. when discord bot died, calls again |
I used the example here to send Audio files. Now I wanted to implement a Skip command which stops the current playback and starts the next one. But I don't really know how to do that with the methods provided.
I tried stopping the stream but then the socket closes and the app crashes with this error:
The text was updated successfully, but these errors were encountered: