我一直在尝试制作一个可以根据不和谐人士的投票使他人静音的服务器。 我在网上看到了不同代码的一部分,并得到了:
const Discord = require('discord.js')
const token = '' ;
const client = new Discord.Client();
const PREFIX = "."
client.on('message', async (msg) => {
var args = msg.content.substring(PREFIX.length).split(" ");
function wait(ms){
var start = new Date().getTime();
var end = start;
while(end < start + ms) {
end = new Date().getTime();
}
}
if(msg.author.equals(client.user)) return;
if (!msg.content.startsWith(PREFIX)) return;
switch (args[0].toLowerCase()) {
case "mute":
const role = msg.guild.roles.cache.find(r => r.name === 'Muted'); // Find Role
if(msg.mentions.members.first().roles.has(role.id)) return
if(!msg.mentions.users.first()) return msg.channel.send('You need to mention somebody!'); // Check if no User was Mentioned
const voting = new Discord.RichEmbed() // Generate Voting Embed
.setColor('#42b34d')
.setFooter('Mute ' + msg.mentions.users.first().tag + ' for 10m?')
.setImage(msg.mentions.users.first().avatarURL);
if(!role) return msg.channel.send('No Role was found, please make sure you have a muteed role!'); // Make sure there is a Role
const agree = '✅'; // Define Emojis
const disagree = '❌'; // Define Emojis
const sentEmbed = await msg.channel.send(voting); // Send Embed
const filter = (reaction, user) => (reaction.emoji.name === agree || reaction.emoji.name === disagree) && !user.bot; // Filter for Reactions
await sentEmbed.react(agree); // React
await sentEmbed.react(disagree); // React
const voteStatus = await msg.channel.send('Voting started 30 seconds left'); // Send start Message and
const collected = await sentEmbed.awaitReactions(filter, { time: 5000 }); // start Collecting Reactions
const agreed = collected.get(agree) || { count: 1 }; // Retrieve Reactions
const disagreed = collected.get(disagree) || { count : 1 }; // Retrieve Reactions
const agreed_count = agreed.count - 1 ; // Count away Bot Votes
const disagreed_count = disagreed.count - 1; // Count away Bot Votes
voteStatus.edit('Voting endet with: ' + agreed_count + agree + ' and ' + disagreed_count + disagree); // Edit message to show Outcome
if(agreed.count > disagreed.count) {
await msg.guild.member(msg.mentions.users.first()).addRole(role);
await wait(600000);
await msg.guild.member(msg.mentions.users.first()).removeRole(role);
}
else {
msg.channel.send('Mute Voting Failed :)');
}
}
})
client.on('ready', () => {
console.log ('Im ready!');
})
client.login("MYKEY");
代码确实正确连接为“我准备好了!”输出到控制台。
使用命令时,我不断收到此错误? error
谢谢!