因此,这是问题的更清晰版本:我正在为我的Discord频道构建一个真相或胆小机器人。而不是添加多个case命令,我将如何制作一个文件(文件中已包含多个问题)并从bot.js中调用它?
这是我的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];
//instead of manually listing, can i create a file and call it from here?
args = args.splice(1);
switch(cmd) {
// !truth
case 'Truth':
bot.sendMessage({
to: channelID,
message: 'What is the most wholesome thing you have ever done'
});
break;
// !dare
case 'Dare':
bot.sendMessage({
to: channelID,
message: 'I dare you to yell yeet at the top of your voice'
});
break;
}
}
});
不是像这样列出消息,有什么方法可以让我调用其中包含多个问题的文件,并让漫游器随机选择它们?