【发布时间】:2019-08-10 18:26:38
【问题描述】:
我想检查用户是否满足命令列出的任何权限。例如,如果所需的权限是 Administrator 或 Manage_Webhooks,并且如果用户只满足其中一个权限,则该命令将运行。
这里有一些代码
if (message.member.guild.me.hasPermission("MANAGE_WEBHOOKS", "ADMINISTRATOR"))
return message.channel.send("I don't have the permissions to make webhooks, please contact an admin or change my permissions!")
if (!message.member.hasPermission("MANAGE_WEBHOOKS", "ADMINISTRATOR")) return message.channel.send("You need to be an admin or webhook manager to use this command.");
如果需要其余的代码,就在这里。
const Discord = require('discord.js');
const commando = require('discord.js-commando');
class pingy extends commando.Command {
constructor(client) {
super(client, {
name: 'pinghook',
group: 'help',
memberName: 'pinghook',
description: 'This is where you can set the pinghook.',
aliases: ['ph', 'pingh', 'phook', 'hook'],
})
}
async run(message, args) {
if (message.member.guild.me.hasPermission("MANAGE_WEBHOOKS", "ADMINISTRATOR"))
return message.channel.send("I don't have the permissions to make webhooks, please contact an admin or change my permissions!")
if (!message.member.hasPermission("MANAGE_WEBHOOKS", "ADMINISTRATOR")) return message.channel.send("You need to be an admin or webhook manager to use this command.");
const avatar = `https://cdn.discordapp.com/attachments/515307677656678420/557050444954992673/Generic5.png`;
const name2 = "PingBot";
const hook = await message.channel.createWebhook(name2, avatar).catch(error => console.log(error))
await hook.edit(name2, avatar).catch(error => console.log(error))
message.channel.send("Your webhook is now created! You can delete it at any time and can be re-added by using this command! You can also edit the webhook's name or avatar.")
setInterval(() => {
hook.send("@everyone you've been pinged.")
}, 500);
}
};
module.exports = pingy;
这就是我想要发生的事情:
当用户运行具有所需权限的命令时,如果用户仅满足其中一项权限,则该命令运行。这同样适用于机器人。它还检查所有角色并查看这些角色中的任何一个是否也符合标准。 (适用于机器人和用户)
实际发生的情况:
该机器人要求用户同时满足自身和用户的权限。在两个用户都满足代码中所需的所有权限之前,机器人不会运行该命令。 bot 仅检查用户的最高角色,而不检查其余角色以查看是否有任何角色满足 required d 权限。
【问题讨论】:
标签: javascript discord.js