Я создаю небольшого бота Discord, который при каждом вводе !lenny
будет отвечать lennyface.Однако у меня проблемы с запуском бота.Это SyntaxError
, что токен недействителен.Любая помощь приветствуется.
Код:
var Discord = require('discord.io');
var logger = require('winston');
var auth = require('./auth');
// 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 'lenny':
bot.sendMessage({
to: channelID,
message: '( ͡° ͜ʖ ͡°)'
});
break;
// Just add any case commands if you want to..
case 'ping':
bot.sendMessage({
to: channelID,
message: 'Pinged!'
});
break;
case 'ver':
bot.sendMessage({
to: channelID,
message: '0.0.4'
});
break;
}
}
});
Вывод:
C:\Users\Terra Byte\Desktop\LennyBot\auth:2
"token": "~~~~~~~~~~~~~~~~~~~~~~"
^
SyntaxError: Unexpected token :
at Module._compile (internal/modules/cjs/loader.js:703:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:770:10)
at Module.load (internal/modules/cjs/loader.js:628:32)
at Function.Module._load (internal/modules/cjs/loader.js:555:12)
at Module.require (internal/modules/cjs/loader.js:666:19)
at require (internal/modules/cjs/helpers.js:16:16)
at Object.<anonymous> (C:\Users\Terra Byte\Desktop\LennyBot\bot.js:3:12)
at Module._compile (internal/modules/cjs/loader.js:759:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:770:10)
at Module.load (internal/modules/cjs/loader.js:628:32)
Я пытался изменить пути к файлам для var auth = require('./auth');
на var auth = require('./auth.json');
, а такжеauth
до auth.json
, это вывод.
C:\Users\Terra Byte\Desktop\LennyBot>node bot.js
C:\Users\Terra Byte\Desktop\LennyBot>
Редактировать: В итоге я использовал более свежий скрипт, и он работает намного лучше.Не удалять, чтобы помочь другим, у которых возникла похожая проблема.