不和谐机器人,为什么它保持脱机状态? [菜鸟]
我已经按照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
应该运行我的机器人,如果我理解正确。可悲的是它保持脱机服务器上。什么我错过了吗?
谢谢 !
回答如下:我想你错过了教程的这一部分在那里它表明你如何让你的auth.json
令牌(下auth.json
部分)。 'YOUR-BOT-TOKEN'
是行不通的。
-----> guide
编辑:此外,OP需要这些额外的依赖,从本教程得到上面的代码工作(见this github discussion):
npm install discord.io github:woor/discord.io#gateway_v6 winston --save
不和谐机器人,为什么它保持脱机状态? [菜鸟]
我已经按照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
应该运行我的机器人,如果我理解正确。可悲的是它保持脱机服务器上。什么我错过了吗?
谢谢 !
回答如下:我想你错过了教程的这一部分在那里它表明你如何让你的auth.json
令牌(下auth.json
部分)。 'YOUR-BOT-TOKEN'
是行不通的。
-----> guide
编辑:此外,OP需要这些额外的依赖,从本教程得到上面的代码工作(见this github discussion):
npm install discord.io github:woor/discord.io#gateway_v6 winston --save