所以我的静音命令遇到了另一个问题,所以问题是当你输入:“?mute @someone”并且没有给出原因或时间时,我收到一个错误,这真的很奇怪。 我已经尽我所能,但我无法让它工作。 代码如下:
var Discord = require('discord.js');
var ms = require('ms');
exports.run = async(client, msg, args) => {
if(!msg.member.hasPermission('MANAGE_MESSAGES')) return msg.reply('You can\'t use that!');
var user = msg.mentions.users.first();
if(!user) return msg.reply('You didn\'t mention anyone!');
var member;
try {
member = await msg.guild.members.fetch(user);
} catch(err) {
member = null;
}
if(!member) return msg.reply('They aren\'t in the server!');
if(member.hasPermission('MANAGE_MESSAGES')) return msg.reply('You cannot mute that person!');
var rawTime = args[1];
var time = ms(rawTime);
if(!time) return msg.reply('You didn\'t specify a time!');
var reason = args.splice(2).join(' ');
if(!reason) return msg.reply('You need to give a reason!');
var channel = msg.guild.channels.cache.find(c => c.name === 'potato');
var log = new Discord.MessageEmbed()
.setTitle('User Muted')
.addField('User:', user, true)
.addField('By:', msg.author, true)
.addField('Expires:', rawTime)
.addField('Reason:', reason)
msg.channel.send(log);
var embed = new Discord.MessageEmbed()
.setTitle('You were muted!')
.addField('Expires:', rawTime, true)
.addField('Reason:', reason, true);
try {
user.send(embed);
} catch(err) {
console.warn(err);
}
var role = msg.guild.roles.cache.find(r => r.id === '862761416255602718');
member.roles.add(role);
setTimeout(async() => {
member.roles.remove(role);
}, time);
}
这是我得到的错误:
(node:1484) UnhandledPromiseRejectionWarning: Error: val is not a non-empty string or a valid number. val=undefined
at module.exports (D:\spil\Firlingdon & xEpic_Wolf Bot\node_modules\ms\index.js:34:9)
at Object.exports.run (D:\spil\Firlingdon & xEpic_Wolf Bot\commands\mute.js:22:16)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:1484) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:1484) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.