我关注了this guide,但该漫游器未联机
我正在使用Raspberry
我已经创建了文件auth.json,package.json和bot.js(下面提供了代码)
npm install discord.io winston --save
在package.json中创建了依赖项
在一个目录中,我具有以下3个文件:
auth.json
{
"token": "blhblhblh.blhblh.blhblhblh"
}
package.json
{
"name": "MyBot123",
"version": "1.0.0",
"description": "Description",
"main": "bot.js",
"author": "author",
"dependencies": {
"discord.io": "^2.5.3",
"winston": "^3.1.0"
}
}
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(new 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..
}
}
});
命令node bot.js
应该运行机器人,但是它执行时没有任何错误消息,并且机器人似乎没有联机。我很困惑,无法调试它,因为我没有使用node.js的经验,因此第一个有效的代码会有所帮助。谢谢!