【发布时间】:2021-05-12 06:29:03
【问题描述】:
这是我做采访命令的尝试。首先,用户必须输入!start 才能让机器人开始对 20 个问题的采访。当用户调用此命令时,机器人会询问第一个问题,然后用户必须回答任何问题才能让机器人继续回答第二个问题,依此类推。
收集器应该在给出答案后发送一个问题,但它根本不起作用。
代码:
const Discord = require('discord.js');
const client = new Discord.Client();
const serverInfo = require('../info.json');
const role = serverInfo.wlRole; // The id of the whit-listed role
const ch = serverIngo.wlChannel; // the id of the white-listed channel for the command to execute
const questions = [
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'10',
'11',
'12',
'13',
'14',
'15',
'16',
'17',
'18',
'19',
'20',
];
const answers = [];
let num = 0;
module.exports = {
name: 'start',
description: 'starts the conversation between the user and the bot',
usage: '!start',
execute(message, args) {
try {
message.delete({
timeout: 1000
});
if (message.channel.id !== ch) return;
const dude = message.guild.members.cache.get(message.author.id);
if (!dude.roles.cache.has(role)) return;
message.author.send('just hang on a sec:clock3: ');
const filter = (m) => m.author.id === message.author.id;
if (num === 0) message.author.send(questions[num]);
// the collector is supposed to send a question after an answer is given but it's not working
const collector = new Discord.Collector(message.author.dmChannel, filter);
collector.on('collect', (msg) => {
answers.push(msg.content);
message.author.send(questions[num]);
console.log(answers);
num++;
});
} catch (error) {
console.log(error);
}
},
};
【问题讨论】:
标签: javascript node.js discord.js