javascript - 案例功能不适用于不和谐机器人
问题描述
我今天开始制作我的不和谐机器人,我完全卡住了,第一个案例完美无缺,但由于某种原因第二个不起作用,我测试了很多次并尝试了不同的东西,但每次我打字!我什么都没有出现也没有错误,所以我不知道。请帮忙。
var Discord = require('discord.io');
var logger = require('winston');
var auth = require('./auth.json');
// Configuring logger settings
logger.remove(logger.transports.Console);
logger.add(new logger.transports.Console, {
colorize: true
});
logger.level = 'debug';
// Initializing 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) {
// 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!'
case 'Mai':
bot.sendMessage({
to: channelID,
messasge:'is the greatest!'
})
});
break;
// Case commands
}
}
});
解决方案
您的开关盒中有一些括号错误。再看看它。
switch(cmd) {
// !ping
case 'ping':
bot.sendMessage({
to: channelID,
message: 'Pong!'
});
break;
case 'Mai':
bot.sendMessage({
to: channelID,
messasge:'is the greatest!'
});
break;