Discord Bot,为什么它保持离线状态? [菜鸟]

时间:2018-05-25 04:39:35

标签: node.js

我跟着this tutorial

我有3个文件:

的package.json

{
"name": "greeter-bot",
"version": "1.0.0",
"description": "My own Discord bot",
"main": "bot.js",
"author": "YOUR-NAME-HERE",
 "dependencies": {}
}

auth.json

{
   "token": "Abcde123blahblah"
}

bot.js

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
});
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..
         }
     }
});

已安装的依赖项:

npm install discord.io winston --save

最后,使用

node bot.js
如果我理解正确,

应该运行我的机器人。可悲的是,它仍然在服务器上脱机。我错过了什么?

谢谢!

1 个答案:

答案 0 :(得分:4)

我认为您错过了教程的这一部分,它向您展示了如何在auth.jsonauth.json部分下)获取令牌。 'YOUR-BOT-TOKEN'不起作用。

- - - - > guide

编辑:此外,OP还需要这些额外的依赖项才能使教程中的上述代码生效(参见this github discussion):

npm install discord.io github:woor/discord.io#gateway_v6 winston --save