izy521 / discord.io

A small, single-file library for creating DiscordApp clients from Node.js or the browser
https://discord.gg/0MvHMfHcTKVVmIGP
MIT License
535 stars 154 forks source link

Bot sometimes works #283

Open githubuser1102 opened 6 years ago

githubuser1102 commented 6 years ago

Sometimes when I do node bot.js it waits at least 5-7 seconds then starts and everything works fine. But sometimes I do it and it starts really fast, and it's detecting stuff in Command Prompt, but is outputting nothing to Discord. This includes the bot's presence (says online but not playing anything) and sending messages. When it does this when I'm running manually to test, I just CTRL+C then up arrow then enter to re-run. But on Heroku, where it restarts every once in a while, I can't control whether it does it correctly or not. Any help is appreciated.

I am on Windows 7 running bot normally from Command Prompt

cloudrac3r commented 6 years ago

Are you using the gateway v6 community fork? (Woor/discord.io)

githubuser1102 commented 6 years ago

Yes, installed a few days ago.

cloudrac3r commented 6 years ago

I've never heard of this happening before. Maybe join the support server and ask there? https://discord.gg/0MvHMfHcTKVVmIGP

githubuser1102 commented 6 years ago

Ok thanks

cloudrac3r commented 6 years ago

For future readers, the solution was to add a disconnect listener.

bot.on("disconnect", () => {
    bot.connect();
});
githubuser1102 commented 6 years ago

Apparently the solution was not to add a disconnect listener. Sorry future readers, still an issue!

bradnak commented 6 years ago

As a troubleshooting step, try changing your disconnect handler to this. It will print an error code and an error message to the console when it disconnects.

bot.on('disconnect', function(errMsg, code) {
    console.log(`Disconnected from Discord. Error Code ${code}. Message ${errMsg}.`
    bot.connect();
}
githubuser1102 commented 6 years ago

Hmm, I tried that but nothing gets outputted into the console. Wondering if it's not picking it up as a disconnect.

githubuser1102 commented 6 years ago

Also your code was missing a ( and a );, so I think I fixed that with

bot.on('disconnect', function(errMsg, code) {
    console.log(`Disconnected from Discord. Error Code ${code}. Message ${errMsg}.`);
    bot.connect();
});
githubuser1102 commented 6 years ago

Never mind, lucky try.