Utils
- novus.utils.try_snowflake(given: list[str] | list[int]) list[int]
- novus.utils.try_snowflake(given: str | int) int
- novus.utils.try_snowflake(given: None) None
Try and turn a given string into a snowflake, returning
Noneif the given value isNone.
- novus.utils.try_id(given: Literal[None]) None
- novus.utils.try_id(given: int | Snowflake | str) int
- novus.utils.try_id(given: list[int] | list[Snowflake] | list[str]) list[int]
Get the ID from the given object if it is a snowflake; return the object unchanged otherwise.
- novus.utils.try_object(given: int | str | Snowflake) Snowflake
- novus.utils.try_object(given: None) None
Wrap the given ID in a
novus.Object, or returnNoneif the item is not an int (or if the object is a snowflake already, return it unchanged).- Parameters:
given (int | novus.abc.Snowflake | None) – The object you want to wrap.
- Returns:
The wrapped object.
- Return type:
Snowflake | None
- novus.utils.walk_components(holders: list[LayoutComponentHolder] | None) Generator[InteractableComponent, None, None]
- novus.utils.parse_timestamp(timestamp: datetime | str | int | Snowflake) DiscordDatetime
- novus.utils.parse_timestamp(timestamp: None) None
Parse a timestamp from Discord.
- Parameters:
timestamp (datetime.datetime | str | int | novus.types.Snowflake | None) – The timstamp to parse. Either a datetime, an ID or an object that follows the snowflake protocol (ie it implements an ID).
- Returns:
A datetime object with an added UTC timezone.
- Return type:
novus.utils.DiscordDatetime
- novus.utils.format_timestamp(timestamp: datetime, style: str | None = None) str
Format a timestamp into a rendered timestamp string.
- Parameters:
timestamp (datetime.datetime) – The timestamp that you want to format.
style (str) –
The format that you want to style the timestamp as.
See also
novus.TimestampFormat
- Returns:
The formatted timestamp.
- Return type:
- novus.utils.now() DiscordDatetime
Get the current timestamp with a timezone applied to it.
Shorthand for
datetime.datetime.now(datetime.timezone.utc).- Returns:
The created datetime.
- Return type: