Skip to content

Class Message

These are the additional methods added to any message instance by pystark. For other methods refer to pyrogram documentation

Message class instances represents messages. This class adds some additional methods to existing pyrogram methods of Message

args: list property readonly

List arguments passed in a message. Removes first word (the command itself)

Parameters:

Name Type Description Default
split str

Define how to split the arguments, defaults to whitespace.

required

Examples:

If text is /start reply user, return value would be ["reply", "user"]

input: str property readonly

Input passed in a message. Removes first word (the command itself)

Examples:

If text is /start reply user, return value would be reply user

ref: Union[int, str] property readonly

Returns the referred user's id or username. To get the full user, use method get_ref_user

Useful to get the referent user's id or username for a command. If command was replied to a message, the replied message's user id is returned. Otherwise, the first argument of command is returned (which isn't guaranteed to be an actual user or an id).

Example:

If command `/ban` was replied to a user's message, user id (`message.reply_to_message.from_user.id`) is returned.

If command `/ban 12345678` was sent, user id (integer) `12345678` is returned.

If command `/ban StarkProgrammer` was sent, username (string) `StarkProgrammer` is returned.

If command `/ban 87654321 12345678` was sent, user id (integer) `87654321` is returned but `12345678` is ignored because it's not the first argument.

If command `/ban` was sent with no arguments and was also not a reply to any message, None is returned.

If command `/ban ok` was sent, "ok" is returned which isn't an actual user but will not raise exception.

get_ref_user(self) async

Returns the full referred user. To get only user id or username, use property ref as it's faster.

Useful to get the referent of a command. If command was replied to a message, the replied message's user is returned. Otherwise, the first argument of command is used to get the user.

Note

If command is not replied then first argument of command is considered user id or username. It's on you to handle PeerIdInvalid and UsernameInvalid

Example:

If command `/ban` was replied to a user's message, user (`message.reply_to_message.from_user`) is returned.

If command `/ban 12345678` was sent, the user instance of user with id `12345678` is returned.

If command `/ban StarkProgrammer` was sent, the user instance of user with username `StarkProgrammer` is returned.

If command `/ban 87654321 12345678` was sent, the user instance of user with id `87654321` is returned but `12345678` is ignored because it's not the first argument.

If command `/ban` was sent with no arguments and was also not a reply to any message, None is returned.

react(self, text, del_in=0, **kwargs) async

React/Reply to a message. Similar to pyrogram's msg.reply but takes care of:

  • Long messages - Sends long messages which raise MESSAGE_TOO_LONG as documents automatically.
  • Localization - For example, if your en.yml file has a HAS_BEENkey thenmessage.react("HAS_BEEN")` will be replaced by it.
  • del_in argument - Extra argument to delete a message after n seconds asynchronously. If n is 0, message is not deleted at all.
Back to top