我有两台服务器,上面有我的机器人和两组朋友。在一台服务器上,机器人和我都有管理员权限,我可以将没有这些权限的人静音。在另一台服务器上,我是所有者,机器人有管理员,但我不能将任何人静音。我收到错误“缺少权限”。
代码如下:
const Discord = require('discord.js')
const ms = require('ms')
module.exports = {
name: 'mute',
execute(message, args) {
if(!args.length) return message.channel.send("Please Specify a time and who to mute. For example, '!mute @antobot10 1d' And then send the command. Once the command is sent, type the reason like a normal message when I ask for it!")
const client = message.client
if (!message.member.hasPermission('MANAGE_ROLES')) return message.channel.send("You don't have permission to use that command!")
else {
const target = message.mentions.members.first();
const filter = (m) => m.author.id === message.author.id
const collector = new Discord.MessageCollector(message.channel, filter, { time: 600000, max: 1 })
const timeGiven = args[1]
message.channel.send('The reason?')
collector.on('collect', m => {
collector.on('end', d => {
const reason = m
message.channel.send(`${target} has been muted`)
target.send(`You have been muted on ${message.guild.name} for the following reason: ***${reason}*** for ${timeGiven}`)
if(message.author.client) return;
})
})
let mutedRole = message.guild.roles.cache.find(role => role.name === "MUTE");
target.roles.add(mutedRole)
setTimeout(() => {
target.roles.remove(mutedRole); // remove the role
target.send('You have been unmuted.')
}, (ms(timeGiven))
)
}
}
}
答案 0 :(得分:0)
如果您的机器人的角色低于您尝试静音的用户的角色,则会出现 missing permissions
错误。在您的服务器设置中,将机器人角色拖放到层次结构中的最高位置。这将解决您的问题。
答案 1 :(得分:0)
好的,我不太确定我做了什么,但是现在可以了。我想我只是更改了它,以便 MUTE 角色具有 0 权限而不是普通权限,但是如果您拥有该角色,则无法在该特定频道中说话。
感谢您的回答!