Checks
function
has_role(role)
¶
Check if the user has the given role.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
role |
Union[int, str, SnowflakeObject, SupportsInt, naff.models.discord.role.Role] |
The Role or role id to check for |
required |
Source code in naff/models/naff/checks.py
def has_role(role: Union[Snowflake_Type, Role]) -> TYPE_CHECK_FUNCTION:
"""
Check if the user has the given role.
Args:
role: The Role or role id to check for
"""
async def check(ctx: Context) -> bool:
if ctx.guild is None:
return False
return ctx.author.has_role(role)
return check
function
has_any_role(*roles)
¶
Checks if the user has any of the given roles.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*roles |
Union[int, str, SnowflakeObject, SupportsInt, naff.models.discord.role.Role] |
The Role(s) or role id(s) to check for |
() |
Source code in naff/models/naff/checks.py
def has_any_role(*roles: Union[Snowflake_Type, Role]) -> TYPE_CHECK_FUNCTION:
"""
Checks if the user has any of the given roles.
Args:
*roles: The Role(s) or role id(s) to check for
"""
async def check(ctx: Context) -> bool:
if ctx.guild is None:
return False
if any(ctx.author.has_role(to_snowflake(r)) for r in roles):
return True
return False
return check
function
has_id(user_id)
¶
Checks if the author has the desired ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
coro |
the function to check |
required |
Source code in naff/models/naff/checks.py
def has_id(user_id: int) -> TYPE_CHECK_FUNCTION:
"""
Checks if the author has the desired ID.
Args:
coro: the function to check
"""
async def check(ctx: Context) -> bool:
return ctx.author.id == user_id
return check
function
is_owner()
¶
Checks if the author is the owner of the bot. This respects the client.owner_ids
list.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
coro |
the function to check |
required |
Source code in naff/models/naff/checks.py
def is_owner() -> TYPE_CHECK_FUNCTION:
"""
Checks if the author is the owner of the bot. This respects the `client.owner_ids` list.
Args:
coro: the function to check
"""
async def check(ctx: Context) -> bool:
_owner_ids: set = ctx.bot.owner_ids.copy()
if ctx.bot.app.team:
[_owner_ids.add(m.id) for m in ctx.bot.app.team.members]
return ctx.author.id in _owner_ids
return check
function
guild_only()
¶
This command may only be ran in a guild.
Source code in naff/models/naff/checks.py
def guild_only() -> TYPE_CHECK_FUNCTION:
"""This command may only be ran in a guild."""
async def check(ctx: Context) -> bool:
return ctx.guild is not None
return check
function
dm_only()
¶
This command may only be ran in a dm.
Source code in naff/models/naff/checks.py
def dm_only() -> TYPE_CHECK_FUNCTION:
"""This command may only be ran in a dm."""
async def check(ctx: Context) -> bool:
return ctx.guild is None
return check