我目前正在处理不和谐的bot poll命令,并且民意测验本身可以正常工作,但是在显示民意测验的结果时遇到了一些麻烦。
async function votingResults(awaitTime) {
const reactions = await msg.awaitReactions(reaction => reaction => reaction.emoji.name === "?" ||
reaction.emoji.name === "?", {time: awaitTime}).catch((err) => {
console.error('Error ' + err);
});
console.log("Ended");
var pollResults = new Discord.MessageEmbed()
.setColor(pink)
.setTitle('POLL ENDED')
.setAuthor('IdealBot', 'https://hypixel.net/attachments/ideal-png.1417277/', 'https://hypixel.net/threads/ideal-ideal-%E2%9D%96-level-52-%E2%9D%96-sweaty-skyblock-guild-%E2%9D%96-top-10-sb-guild-%E2%9D%96-splashes-%E2%9D%96-events-%E2%9D%96-recruiting.2500755/')
.addFields(
{ name: 'Question', value: pollArgs[0] },
{ name: '\u200B', value: '\u200B' }
)
.setTimestamp()
.setFooter('Ideal bot v 1.2 [BETA]');
for (i = 2; i < pollArgs.length; i++) {
console.log(reactions);
pollResults.addFields({ name: 'Option ' + pollReact[i - 2], value: pollArgs[i] + `\nVotes: **${reactions.get(pollReact[i-2])-1}**`, inline: true });
}
pollResults.addFields({ name: '\u200B', value: '\u200B' });
msg.channel.send(pollResults).catch((err) => {
console.error('Error!' + err);
})
}
module.exports.run = async (client, message, args) => {
msg = message;
if (message.channel.id == '689423653389336636' || message.channel.id == '691039595348885564' || message.channel.id == '693094055533346826') {
if (args.length < 8) {
message.channel.send(pollUsage);
message.delete();
}
else {
pollMsg = message.content.slice(6, message.length);
pollArgs = pollMsg.split("/"); // Splits arguments by "/"
if (pollArgs.length > 11) {
message.channel.send(pollUsage);
message.delete();
}
else {
var timeArgs = pollArgs[1].split(":");
var days = parseInt(timeArgs[0]);
var hours = parseInt(timeArgs[1]);
var minutes = parseInt(timeArgs[2]);
var seconds = parseInt(timeArgs[3]);
if (timeArgs.length < 5) {
var pollEmbed = new Discord.MessageEmbed()
.setColor(pink)
.setTitle('POLL')
.setAuthor('IdealBot', 'https://hypixel.net/attachments/ideal-png.1417277/', 'https://hypixel.net/threads/ideal-ideal-%E2%9D%96-level-52-%E2%9D%96-sweaty-skyblock-guild-%E2%9D%96-top-10-sb-guild-%E2%9D%96-splashes-%E2%9D%96-events-%E2%9D%96-recruiting.2500755/')
.addFields(
{ name: 'Question', value: pollArgs[0] },
{ name: '\u200B', value: '\u200B' }
)
.setTimestamp()
.setFooter('Time left: ' + pollArgs[1]);
for (i = 2; i < pollArgs.length; i++) {
pollEmbed.addFields({ name: 'Option ' + pollReact[i - 2], value: pollArgs[i], inline: true });
}
pollEmbed.addFields({ name: '\u200B', value: '\u200B' });
var secDays = days * 24 * 60 * 60;
var secHours = hours * 60 * 60;
var secMinutes = minutes * 60;
console.log("New poll successfully created! Ending in " + pollArgs[1] + "!");
var totalTime = secDays + secHours + secMinutes + seconds;
var totalTimeMilliseconds = totalTime * 1000;
var currentTime = new Date().getTime();
var endDate = currentTime + totalTimeMilliseconds;
msg = message.channel.send(pollEmbed).then(sentEmbed => {
for (i = 2; i < pollArgs.length; i++) {
sentEmbed.react(pollReactEmoji[i - 2])
}
votingResults(totalTimeMilliseconds);
var timer = setInterval(function () {
var currentTime = new Date().getTime();
var remainingTime = endDate - currentTime;
if (remainingTime >= 0) {
let daysCalc = Math.floor(remainingTime / (1000 * 60 * 60 * 24));
let hoursCalc = Math.floor((remainingTime % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
let minutesCalc = Math.floor((remainingTime % (1000 * 60 * 60)) / (1000 * 60));
let secondsCalc = Math.floor((remainingTime % (1000 * 60)) / 1000);
if (daysCalc < 10) { daysCalc = "0" + daysCalc };
if (hoursCalc < 10) { hoursCalc = "0" + hoursCalc };
if (minutesCalc < 10) { minutesCalc = "0" + minutesCalc };
if (secondsCalc < 10) { secondsCalc = "0" + secondsCalc };
var remainingTimeText = daysCalc + ":" + hoursCalc + ":" + minutesCalc + ":" + secondsCalc;
pollEmbed.setFooter('Time left: ' + remainingTimeText);
sentEmbed.edit(pollEmbed).catch((err) => {
console.error('Error! ' + err);
})
}
else {
pollEmbed.setFooter('Poll expired!');
sentEmbed.edit(pollEmbed).catch((err) => {
console.error('Error!' + err);
})
}
}, 1000);
}).catch((err) => {
console.error('Error! ' + err)
})
message.delete();
}
}
}
}
}
每当我尝试运行代码时,都会出现错误:
TypeError:msg.awaitReactions不是函数
我不明白这一点,因为我将msg
定义为消息。