Перейти к содержанию

Message

Represents a message in MAX messenger.

Attributes

Attribute Type Description
id int Unique message identifier
chat Chat Chat where the message was sent
from_user User Sender of the message
text str Text content of the message
date datetime Date when the message was sent
reply_to_message Message Replied message (if any)

Methods

reply(text, **kwargs)

Reply to this message.

@bot.on_message()
async def handle(message):
    await message.reply("Hello!")

forward(chat_id)

Forward this message to another chat.

@bot.on_message()
async def handle(message):
    await message.forward(chat_id=ADMIN_CHAT_ID)

delete()

Delete this message.

@bot.on_message()
async def handle(message):
    await message.delete()

edit_text(text)

Edit the text of this message.

@bot.on_callback_query()
async def handle(callback):
    await callback.message.edit_text("Updated!")

Example

@bot.on_message()
async def echo_with_reply(message):
    # Reply to the message
    await message.reply(f"You said: {message.text}")

    # Access sender info
    username = message.from_user.username

    # Access chat info
    chat_title = message.chat.title

See Also

  • Chat - Chat information
  • User - User information
  • Update - Update object