Skip to content

Commit 93018a7

Browse files
committed
Add set_profile_photo method
1 parent 474388d commit 93018a7

2 files changed

Lines changed: 49 additions & 0 deletions

File tree

pyrogram/client/methods/users/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@
2020
from .get_me import GetMe
2121
from .get_user_profile_photos import GetUserProfilePhotos
2222
from .get_users import GetUsers
23+
from .set_profile_photo import SetProfilePhoto
2324

2425

2526
class Users(
2627
GetUserProfilePhotos,
28+
SetProfilePhoto,
2729
DeleteProfilePhotos,
2830
GetUsers,
2931
GetMe
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Pyrogram - Telegram MTProto API Client Library for Python
2+
# Copyright (C) 2017-2018 Dan Tès <https://github.com/delivrance>
3+
#
4+
# This file is part of Pyrogram.
5+
#
6+
# Pyrogram is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU Lesser General Public License as published
8+
# by the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# Pyrogram is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU Lesser General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU Lesser General Public License
17+
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
18+
19+
from pyrogram.api import functions
20+
from ...ext import BaseClient
21+
22+
23+
class SetProfilePhoto(BaseClient):
24+
def set_profile_photo(self, photo: str):
25+
"""Use this method to set a new profile photo.
26+
27+
This method only works for Users. Bots profile photos must be set using BotFather.
28+
29+
Args:
30+
photo (``str``):
31+
Profile photo to set.
32+
Pass a file path as string to upload a new photo that exists on your local machine.
33+
34+
Returns:
35+
True on success.
36+
37+
Raises:
38+
:class:`Error <pyrogram.Error>`
39+
"""
40+
41+
return bool(
42+
self.send(
43+
functions.photos.UploadProfilePhoto(
44+
self.save_file(photo)
45+
)
46+
)
47+
)

0 commit comments

Comments
 (0)