discord.message module

class discord.message.Message(content, channel_id, author_id, username, timestamp=None, attachment=None, embed=None, mentions=None)[source]

Bases: object

A discord message as described here: https://discordapp.com/developers/docs/resources/channel#message-object A message can be either received through the gateway websocket or sent to the REST API.

Parameters:
  • content – The contents of the message.
  • channel_id – The id of the channel the message will be written to.
  • author_id – The unique id of the user who sent/sends the message.
  • username – The current username#discriminator combo for that user.
  • timestamp – The time of the message.
  • attachment – The file that will be attached to the message.
  • embed – # TODO: document.
  • mentions – A list of users mentioned in the message.
static from_payload(payload)[source]

Creates a Message from a Payload by extracting relevant items.

Parameters:payload – A MESSAGE_CREATE payload.
Returns:A message.
to_payload()[source]

Encodes the message into a payload-like dictionary, a format recognized by discord’s APIs.

Returns:A payload dictionary.
to_json()[source]

Encodes the message in json in a format recognized by discord’s APIs.

Returns:A json string.