我在discord.js v12.5.3静音命令上遇到一个错误



当我运行此代码时,它会给我一个错误,我一直在互联网上寻找解决方案,但我就是无法让它工作!如果你想帮助我,请帮助我!

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);
msg.channel.send(`**${user}** has been muted by **${msg.author}** for **${rawTime}**!`);
}

这是我得到的错误:(这是我运行它时得到的错误(

(node:23408) UnhandledPromiseRejectionWarning: DiscordAPIError: Missing Permissions
at RequestHandler.execute (D:spilFirlingdon & xEpic_Wolf Botnode_modulesdiscord.jssrcrestRequestHandler.js:154:13)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async RequestHandler.push (D:spilFirlingdon & xEpic_Wolf Botnode_modulesdiscord.jssrcrestRequestHandler.js:39:14)
at async GuildMemberRoleManager.add (D:spilFirlingdon & xEpic_Wolf Botnode_modulesdiscord.jssrcmanagersGuildMemberRoleManager.js:96:7)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:23408) 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:23408) [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.
(node:23408) UnhandledPromiseRejectionWarning: DiscordAPIError: Missing Permissions

这是我在10秒后得到的代码:

at RequestHandler.execute (D:spilFirlingdon & xEpic_Wolf Botnode_modulesdiscord.jssrcrestRequestHandler.js:154:13)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async RequestHandler.push (D:spilFirlingdon & xEpic_Wolf Botnode_modulesdiscord.jssrcrestRequestHandler.js:39:14)
at async GuildMemberRoleManager.remove (D:spilFirlingdon & xEpic_Wolf Botnode_modulesdiscord.jssrcmanagersGuildMemberRoleManager.js:125:7)
(node:23408) 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: 2)

第一个想法:您给出了错误的使用权限。机器人程序的合适权限是:"MANAGE_ROLES",而用户的合适权限则是:"MUTE_MEMBERS",我强烈建议这样做。

if(!msg.guild.me.hasPermission('MANAGE_ROLES'){
return msg.reply(`blahblah`)
}

第二个想法:你可能真的在屏蔽自己,或者在管理员身上。在没有权限使用"MUTE_MEMBERS"的人身上测试它。我非常强烈地建议在ALT上做这件事,因为它可以帮助很多问题。

第三个想法:你给机器人的角色还不够,也许可以让它成为服务器中尽可能高的角色(就像在服务器的顶部一样(,并测试谁没有perms或ALT。

第四个想法:你的角色可能是错误的,我强烈建议使用这个代码:

let role = msg.guild.roles.cache.get(`id`)
memeber.roles.add(role)
member.roles.remove(role)

或者你的会员代码可能是错误的,试着这样做:


member = await msg.guild.members.cache.get(user.id)

在错误代码上这样做:

member = null
console.log(err) //so you know what errors it out here.

我希望这些想法对你有帮助<3

最新更新