Message Parser Implementation

Parser implementations for disnake message types.

Classes

class disnake_compass.impl.parser.message.PartialMessageParser(int_parser=NOTHING, *, channel=None)[source]

Bases: Parser[PartialMessage]

Parser type with support for partial messages.

Parameters:
  • int_parser (IntParser) – The IntParser to use internally for this parser.

  • channel (SupportsGetPartialMessage | None) –

    The channel in which to make the partial message.

    Defaults to None. If left to be None, loads() will attempt to get a channel from the source.

Attributes

channel: SupportsGetPartialMessage | None

The channel in which to make the partial message.

int_parser: IntParser

The IntParser to use internally for this parser.

Since the default integer parser uses base-36 to “compress” numbers, the default guild parser will also return compressed results.

Methods

await dumps(argument, /)[source]

Dump a partial message into a string.

This uses the underlying int_parser.

Parameters:

argument (PartialMessage) – The value that is to be dumped.

await loads(argument, /)[source]

Load a partial message from a string.

This uses the underlying int_parser.

Parameters:

argument (str) – The value that is to be loaded into a partial message.

Raises:

RuntimeErrorchannel was not set, and no channel could be obtained from the source.

class disnake_compass.impl.parser.message.MessageParser(int_parser=NOTHING, *, allow_api_requests=True)[source]

Bases: Parser[Message]

Asynchronous parser type with support for messages.

Warning

This parser can make API requests.

Parameters:
  • int_parser (IntParser) – The IntParser to use internally for this parser.

  • allow_api_requests (bool) – Whether or not to allow this parser to make API requests.

Attributes

allow_api_requests: bool

Whether or not to allow this parser to make API requests.

Parsers will always try getting a result from cache first.

int_parser: IntParser

The IntParser to use internally for this parser.

Since the default integer parser uses base-36 to “compress” numbers, the default guild parser will also return compressed results.

Methods

await dumps(argument, /)[source]

Dump a message into a string.

This uses the underlying int_parser.

Parameters:

argument (Message) – The value that is to be dumped.

await loads(argument, /)[source]

Load a message from a string.

This uses the underlying int_parser.

This method first tries to get the message from cache. If this fails, it will try to fetch the message instead.

Warning

This method can make API requests.

Parameters:

argument (str) – The value that is to be loaded into a message.

Raises:

LookupError – A message with the id stored in the argument could not be found.