Send Random Messages to Chats with Telethon

  • Share this:

Code introduction


This function uses the Telethon library to send a random message to a specified chat room. It takes a session object, a chat ID, and a message content as parameters.


Technology Stack : Telethon

Code Type : Telethon API Usage

Code Difficulty : Intermediate


                
                    
def send_random_message(session, chat_id, message):
    from telethon.tl.functions.messages import SendMessageRequest
    from telethon.tl.types import InputPeerUser

    # Send a random message to the specified chat using the provided session and chat_id
    user_input = InputPeerUser(chat_id, 0)
    session.send_message(user_input, message)                
              
Tags: