为什么我的权限检查(Discordia bot)总是返回 false?

时间:2021-01-04 20:43:42

标签: lua discord

问题出在第 10 行。无论我拥有什么角色或权限,我总是从我的机器人收到“您没有管理员或所需角色(测试消息)”消息。我认为这是因为我使用了“and”而不是“or”,但这只是解决了以前的问题(无论我有什么权限或是否有管理员,我都会被批准使用该命令)。有人可以解释我做错了什么吗? 编辑:我需要使用“and”而不是“or”,并且我没有确保从我用来测试这个的备用帐户中删除管理员。

client:on("messageCreate", function(message)
        if message.author.bot == true then 
        return end

    local author = message.guild:getMember(message.author.id)
    local authorRole = message.guild:getMember(message.member)

    if message.content == prefix.."Permissions" then
        for i, v in ipairs(roleswithpermission) do
            if not author:hasPermission("administrator") or not authorRole:hasRole(v) then
                message.channel:send("You don't have admin or the role required (test message)")
            elseif author:hasPermission("administrator") or authorRole:hasRole(v) then
                message.channel:send("This is a test message (means the permission check worked and you have permission)")
            end
        end 
    end     
end)

1 个答案:

答案 0 :(得分:0)

您不应该使用 for 循环来检查所有具有权限的 discord 角色,而不是遍历所有权限,您可以只检查成员是否具有特定权限或角色。

if message.member:hasPermission("administrator") or message.member:hasRole("Role Id") then
    print("True")
else
    print("False")
end

也不要使用会员 ID 来检查权限。我很确定您不能使用 hasRole() 检查角色的名称,因为它只检查角色 ID。

相关问题