GoldyBot.objects.role
1from __future__ import annotations 2import nextcord 3 4import GoldyBot 5from GoldyBot.errors import FailedToFindRole 6from GoldyBot.objects.slash import Interaction, InteractionToCtx 7 8class Role(): 9 """ 10 A class representing a discord role in Goldy Bot. Either 'role_id', 'role_name', 'mention_str' or 'role_object' has to be passed in the 'Role()'. 11 12 Raises FailedToFindRole() when role is not found. 13 """ 14 def __init__(self, ctx, role_id:str=None, role_name:str=None, role_object:nextcord.Role=None, mention_str:str=None): 15 self.ctx = ctx 16 self.role_id_ = role_id 17 self.role_name_ = role_name 18 self.mention_str_ = mention_str 19 self.role_object_ = role_object 20 21 self.role_ = None 22 23 if self.role_object_ == None: 24 self.role_ = self.find_role(self.role_id, self.role_name_) 25 else: 26 self.role_ = self.role_object_ 27 28 @property 29 def role(self) -> nextcord.Role: 30 """Returns the actual representation of the role in nextcord.""" 31 return self.role_ 32 33 @property 34 def role_id(self) -> str|None: 35 """Returns id of discord role. Returns ``None`` if ``role_id``, ``role_name``, ``mention_str`` and ``role_object`` are left blank.""" 36 if not self.role_id_ == None: return str(self.role_id_) 37 if not self.mention_str_ == None: return self.mention_str_[3:-1] 38 if not self.role_object_ == None: return str(self.role_object_.id) 39 40 return None 41 42 @property 43 def role_name(self) -> str: 44 """Returns the name of the role.""" 45 return self.role.name 46 47 def find_role(self, role_id:int|str, role_name:str=None) -> nextcord.Role: 48 role:nextcord.Role 49 50 if role_name == None: 51 if not role_id == None: 52 role = self.ctx.guild.get_role(int(role_id)) 53 else: 54 role = None 55 56 if role == None: 57 raise FailedToFindRole(option_used="id", option_value=role_id) 58 else: 59 GoldyBot.logging.log(f"Found the role '{role.name}' by id.") 60 return role 61 62 else: 63 role = nextcord.utils.get(self.ctx.guild.roles, name=role_name) 64 65 if role == None: 66 raise FailedToFindRole(option_used="role name", option_value=role_name) 67 else: 68 GoldyBot.logging.log(f"Found the role '{role.name}' by name.") 69 return role
class
Role:
9class Role(): 10 """ 11 A class representing a discord role in Goldy Bot. Either 'role_id', 'role_name', 'mention_str' or 'role_object' has to be passed in the 'Role()'. 12 13 Raises FailedToFindRole() when role is not found. 14 """ 15 def __init__(self, ctx, role_id:str=None, role_name:str=None, role_object:nextcord.Role=None, mention_str:str=None): 16 self.ctx = ctx 17 self.role_id_ = role_id 18 self.role_name_ = role_name 19 self.mention_str_ = mention_str 20 self.role_object_ = role_object 21 22 self.role_ = None 23 24 if self.role_object_ == None: 25 self.role_ = self.find_role(self.role_id, self.role_name_) 26 else: 27 self.role_ = self.role_object_ 28 29 @property 30 def role(self) -> nextcord.Role: 31 """Returns the actual representation of the role in nextcord.""" 32 return self.role_ 33 34 @property 35 def role_id(self) -> str|None: 36 """Returns id of discord role. Returns ``None`` if ``role_id``, ``role_name``, ``mention_str`` and ``role_object`` are left blank.""" 37 if not self.role_id_ == None: return str(self.role_id_) 38 if not self.mention_str_ == None: return self.mention_str_[3:-1] 39 if not self.role_object_ == None: return str(self.role_object_.id) 40 41 return None 42 43 @property 44 def role_name(self) -> str: 45 """Returns the name of the role.""" 46 return self.role.name 47 48 def find_role(self, role_id:int|str, role_name:str=None) -> nextcord.Role: 49 role:nextcord.Role 50 51 if role_name == None: 52 if not role_id == None: 53 role = self.ctx.guild.get_role(int(role_id)) 54 else: 55 role = None 56 57 if role == None: 58 raise FailedToFindRole(option_used="id", option_value=role_id) 59 else: 60 GoldyBot.logging.log(f"Found the role '{role.name}' by id.") 61 return role 62 63 else: 64 role = nextcord.utils.get(self.ctx.guild.roles, name=role_name) 65 66 if role == None: 67 raise FailedToFindRole(option_used="role name", option_value=role_name) 68 else: 69 GoldyBot.logging.log(f"Found the role '{role.name}' by name.") 70 return role
A class representing a discord role in Goldy Bot. Either 'role_id', 'role_name', 'mention_str' or 'role_object' has to be passed in the 'Role()'.
Raises FailedToFindRole() when role is not found.
Role( ctx, role_id: str = None, role_name: str = None, role_object: nextcord.role.Role = None, mention_str: str = None)
15 def __init__(self, ctx, role_id:str=None, role_name:str=None, role_object:nextcord.Role=None, mention_str:str=None): 16 self.ctx = ctx 17 self.role_id_ = role_id 18 self.role_name_ = role_name 19 self.mention_str_ = mention_str 20 self.role_object_ = role_object 21 22 self.role_ = None 23 24 if self.role_object_ == None: 25 self.role_ = self.find_role(self.role_id, self.role_name_) 26 else: 27 self.role_ = self.role_object_
def
find_role(self, role_id: int | str, role_name: str = None) -> nextcord.role.Role:
48 def find_role(self, role_id:int|str, role_name:str=None) -> nextcord.Role: 49 role:nextcord.Role 50 51 if role_name == None: 52 if not role_id == None: 53 role = self.ctx.guild.get_role(int(role_id)) 54 else: 55 role = None 56 57 if role == None: 58 raise FailedToFindRole(option_used="id", option_value=role_id) 59 else: 60 GoldyBot.logging.log(f"Found the role '{role.name}' by id.") 61 return role 62 63 else: 64 role = nextcord.utils.get(self.ctx.guild.roles, name=role_name) 65 66 if role == None: 67 raise FailedToFindRole(option_used="role name", option_value=role_name) 68 else: 69 GoldyBot.logging.log(f"Found the role '{role.name}' by name.") 70 return role