You can download this code by clicking the button below.
This code is now available for download.
This function is used to send a random sticker in a specified chat. It first determines the input type based on the target (either user ID or chat ID), and then sends the sticker using `SendMediaRequest` and `InputPeerUser` or `InputPeerChat` from the Telethon library.
Technology Stack : Telethon
Code Type : Function
Code Difficulty : Intermediate
def send_random_sticker(chat, sticker):
from telethon.tl.functions.messages import SendMediaRequest
from telethon.tl.types import InputPeerUser, InputPeerChat
def get_inputPeer(target):
if isinstance(target, str):
return InputPeerUser(target)
elif isinstance(target, int):
return InputPeerChat(target)
inputPeer = get_inputPeer(chat)
sendMediaRequest = SendMediaRequest(inputPeer, sticker)
chat.send_message(sendMediaRequest)