gpt4 book ai didi

javascript - 案例功能不适用于不和谐机器人

转载 作者:行者123 更新时间:2023-12-01 00:16:38 27 4
gpt4 key购买 nike

我今天开始制作我的不和谐机器人,我完全陷入困境,第一个案例工作完美,但由于某种原因第二个案例不起作用,我测试了很多次并尝试不同的事情,但每次我输入!Mai什么也没有出现了,也没有错误,所以我不知道。请帮忙。

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 语句时犯了一些错误:

  • 关键消息中有拼写错误
  • 你的括号放错了
  • 每个案例都应该有一个中断

您的声明应如下所示:

switch(cmd) {
// !ping
case 'ping':
bot.sendMessage({
to: channelID,
message: 'Pong!'
});
break;
case 'Mai':
bot.sendMessage({
to: channelID,
message:'is the greatest!'
});
break;
// Case commands
}

关于javascript - 案例功能不适用于不和谐机器人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59718134/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com