I've been coding a Poll Command for my Discord Bot. It is in Discord.JS but when I am going to run the command, it does this error:
I've been trying to fix this issue for a while and it still does this issue. I've changed some lines of code, particularly line 65 and line 70-80.
Code:
const options = [
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
];
const pollLog = {};
function canSendPoll(user_id) {
if (pollLog[user_id]) {
const timeSince = Date.now() - pollLog[user_id].lastPoll;
if (timeSince < 1) {
return false;
}
}
return true;
}
exports.run = async (client, message, args, level, Discord) => {
if (args) {
if (!canSendPoll(message.author.id)) {
return message
.channel
.send(`${message.author} please wait before sending another poll.`);
} else if (args.length === 1) { // yes no unsure question
const question = args[0];
pollLog[message.author.id] = {
lastPoll: Date.now()
};
return message
.channel
.send(`${message.author} asks: ${question}`)
.then(async (pollMessage) => {
await pollMessage.react('');
await pollMessage.react('');
await pollMessage.react(message.guild.emojis.get('475747395754393622'));
});
} else { // multiple choice
args = args.map(a => a.replace(/"/g, ''));
const question = args[0];
const questionOptions = message.content.match(/"(.+?)"/g);
if (questionOptions.length > 20) {
return message.channel.send(`${message.author} Polls are limited to 20 options.`);
} else {
pollLog[message.author.id] = {
lastPoll: Date.now()
};
return message
.channel
.send(`${message.author} asks: ${question}
${questionOptions
.map((option, i) => `${options[i]} - ${option}`).join('\n')}
`)
.then(async (pollMessage) => {
for (let i = 0; i < questionOptions.length; i++) {
await pollMessage.react(options[i]);
}
});
}
}
} else {
return message.channel.send(`**Poll |** ${message.author} invalid Poll! Question and options should be wrapped in double quotes.`);
}
}