diff --git a/aiogram/types/chat.py b/aiogram/types/chat.py index b956f4ba..cde24548 100644 --- a/aiogram/types/chat.py +++ b/aiogram/types/chat.py @@ -28,6 +28,7 @@ if TYPE_CHECKING: SendChatAction, SetChatAdministratorCustomTitle, SetChatDescription, + SetChatMemberTag, SetChatPermissions, SetChatPhoto, SetChatStickerSet, @@ -967,6 +968,38 @@ class Chat(TelegramObject): **kwargs, ).as_(self._bot) + def set_member_tag( + self, + user_id: int, + tag: str | None = None, + **kwargs: Any, + ) -> SetChatMemberTag: + """ + Shortcut for method :class:`aiogram.methods.set_chat_member_tag.SetChatMemberTag` + will automatically fill method attributes: + + - :code:`chat_id` + + Use this method to set a tag for a regular member in a group or a supergroup. The bot must be an administrator in the chat for this to work and must have the *can_manage_tags* administrator right. Returns :code:`True` on success. + + Source: https://core.telegram.org/bots/api#setchatmembertag + + :param user_id: Unique identifier of the target user + :param tag: New tag for the member; 0-16 characters, emoji are not allowed + :return: instance of method :class:`aiogram.methods.set_chat_member_tag.SetChatMemberTag` + """ + # DO NOT EDIT MANUALLY!!! + # This method was auto-generated via `butcher` + + from aiogram.methods import SetChatMemberTag + + return SetChatMemberTag( + chat_id=self.id, + user_id=user_id, + tag=tag, + **kwargs, + ).as_(self._bot) + def set_permissions( self, permissions: ChatPermissions, diff --git a/tests/test_api/test_methods/test_set_chat_member_tag.py b/tests/test_api/test_methods/test_set_chat_member_tag.py new file mode 100644 index 00000000..4c6e4fd6 --- /dev/null +++ b/tests/test_api/test_methods/test_set_chat_member_tag.py @@ -0,0 +1,11 @@ +from aiogram.methods import SetChatMemberTag +from tests.mocked_bot import MockedBot + + +class TestSetChatMemberTag: + async def test_bot_method(self, bot: MockedBot): + prepare_result = bot.add_result_for(SetChatMemberTag, ok=True, result=True) + + response: bool = await bot.set_chat_member_tag(chat_id=-42, user_id=42, tag="test") + bot.get_request() + assert response == prepare_result.result diff --git a/tests/test_api/test_types/test_chat.py b/tests/test_api/test_types/test_chat.py index 360b2ee1..b3e63854 100644 --- a/tests/test_api/test_types/test_chat.py +++ b/tests/test_api/test_types/test_chat.py @@ -115,6 +115,14 @@ class TestChat: method = chat.set_administrator_custom_title(user_id=1, custom_title="test") assert method.chat_id == chat.id + def test_set_member_tag(self): + chat = Chat(id=-42, type="supergroup") + + method = chat.set_member_tag(user_id=42, tag="test") + assert method.chat_id == chat.id + assert method.user_id == 42 + assert method.tag == "test" + def test_set_permissions(self): chat = Chat(id=-42, type="supergroup")