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 155 forks source link

node bot.js not working #234

Closed StopPls closed 6 years ago

StopPls commented 6 years ago

I cannot host my bot via node, My bot code was working just fine last night(I even let my bot run through the night) but now when I try to node my bot it doesn't do anything, it just pauses for a second and does nothing. However, it does do things that are outside of the discord.io events, which has led me to believe that its a discord.io problem.

Source code(a tutorial bot I found online) var Discord = require('discord.io'); var logger = require('winston'); var auth = require('./auth.json'); // Configure logger settings logger.remove(logger.transports.Console); logger.add(logger.transports.Console, { colorize: true }); logger.level = 'debug'; // Initialize Discord Bot var bot = new Discord.Client({ token: auth.token, autorun: true }); logger.info('Initialized'); bot.on('ready', function (evt) { logger.info('Connected'); logger.info('Logged in as: '); logger.info(bot.username + ' - (' + bot.id + ')'); }); bot.on('message', function (user, userID, channelID, message, evt) { // Our bot needs to know if it will execute a command // It will listen for messages that will start with ! if (message.substring(0, 1) == '!') { var args = message.substring(1).split(' '); var cmd = args[0];

    args = args.splice(1);
    switch(cmd) {
        // !ping
        case 'ping':
            bot.sendMessage({
                to: channelID,
                message: 'Pong!'
            });
        break;
        // Just add any case commands if you want to..
     }
 }

});

Output:"info: Initialized"

before the output also did the information inside of bot.on('ready') and bot.on('message')

metadan commented 6 years ago

I think maybe this is a discord issue

weq commented 6 years ago

I don't think this is a discord issue. Because if I try the quick example with Discord.io it is still broken. But other Discord JS frameworks works just fine. So if discord has done something discord.io haven't been updated to conform.

gaviarctica commented 6 years ago

Discord's gateway protocol version 5, which discord.io uses, seems to be discontinued: https://discordapp.com/developers/docs/topics/gateway

I got my bot working by changing line 5 of index.js from GATEWAY_VERSION = 5, to GATEWAY_VERSION = 6,

Also some channel type checks weren't working anymore since the types have apparently changed from 'text' and 'voice' to 0 and 2 respectively. So I changed those values too eg. the line if (channel.type !== 'voice') return handleErrCB(("Selected channel is not a voice channel: " + channelID), callback); to if (channel.type !== 2) return handleErrCB(("Selected channel is not a voice channel: " + channelID), callback);

With these changes it is working for my use case at least.

izy521 commented 6 years ago

The NPM version of the lib is indeed out of date. The gateway it was using was shut-down in October. However, previously, Discord implicitly moved someone, using an out-of-date gateway version, to a current gateway version, automatically. This doesn't seem to be the case anymore, and it now kicks you off, and gives you the new 4012 gateway error code.

I can't update the NPM version until the https://github.com/izy521/discord.io/tree/next branch is finished. So you can use the git version of discord.io from this repo, or use npm install woor/discord.io#gateway_v6.

AnnanFay commented 6 years ago

One remaining problem is:

now when I try to node my bot it doesn't do anything, it just pauses for a second and does nothing.

I just tried using this library today for the first time. Eventually I figured it out. But after it running silently I had no idea if it was failing because I didn't install node correctly, or because a firewall was blocking the connection, or because I was using V9 version of node instead of V8.

AlekEagle commented 6 years ago

im using it right now, and after i tried to use bot.user.setStatus('On This Server'); it stopped working completely, it doesn't even output to a log anymore.