hasRole

fun Member.hasRole(id: Long): Boolean

Check if a member has a role by the id of the role

Return

true if they have it, false if not

Samples

import dev.jaims.kda.user.hasRole
import net.dv8tion.jda.api.entities.Member
import net.dv8tion.jda.api.entities.Role
fun main() { 
   //sampleStart 
   if (!member.hasRole(yourRole)) return
// member has permission! 
   //sampleEnd
}

Parameters

id

the id of the role to check

fun Member.hasRole(role: Role): Boolean

Check if a memebr has a role by the id of the role

Return

true if they have it, false if not

Samples

import dev.jaims.kda.user.hasRole
import net.dv8tion.jda.api.entities.Member
import net.dv8tion.jda.api.entities.Role
fun main() { 
   //sampleStart 
   if (!member.hasRole(yourRole)) return
// member has permission! 
   //sampleEnd
}

Parameters

role

the role to check

fun Member.hasRole(ids: List<Long>): Boolean

Check if a Member has a role in a list of roles

Return

true if they have at least one role, false if they don't have any of the roles

Samples

import dev.jaims.kda.user.hasRole
import net.dv8tion.jda.api.entities.Member
import net.dv8tion.jda.api.entities.Role
fun main() { 
   //sampleStart 
   if (!member.hasRole(yourRole)) return
// member has permission! 
   //sampleEnd
}

Parameters

ids

the list of role ids

fun User.hasRole(id: Long, guild: Guild): Boolean?

Check if a user has a role in a specific guild Will require that the user is cached to return true / false

Return

null if not in the guild or not cached. otherwise, true if they have the role, false if not

Parameters

id

the role's id

guild

the guild to check in

fun User.hasRole(role: Role, guild: Guild): Boolean?

Check if a user has a role in a specific guild Will require that the user is cached to return true / false

Return

null if not in the guild or not cached. otherwise, true if they have the role, false if not

Parameters

role

the role

guild

the guild to check in

fun User.hasRole(ids: List<Long>, guild: Guild): Boolean?

Check if a user has any role in a list for a specific guild

Return

null if not in guild or not cached. true if they have at least one of the roles, false if they don't have one

Parameters

ids

the list of ids to check

guild

the guild to check in