async def set_telegram_username(self, source: 'u.User', username: str) -> None: if self.peer_type != "channel": raise ValueError("Only channels and supergroups have usernames.") await source.client( UpdateUsernameRequest(await self.get_input_entity(source), username)) if await self._update_username(username): self.save()
async def grabUsername(e): global inGrab await e.edit( "__Il processo di grab è stato avviato! Per stopparlo usa .stopgrab__") inGrab = True createdPrivateChannel = await bot( CreateChannelRequest("BlackList", "BlackList", megagroup=False)) newChannelID = createdPrivateChannel.__dict__["chats"][0].__dict__["id"] newChannelAccessHash = createdPrivateChannel.__dict__["chats"][0].__dict__[ "access_hash"] desiredPublicUsername = e.text.split(" ", 1)[1].replace("@", "") while inGrab: try: checkUsernameResult = await bot( CheckUsernameRequest( InputPeerChannel(channel_id=newChannelID, access_hash=newChannelAccessHash), desiredPublicUsername)) if checkUsernameResult: publicChannel = await bot( UpdateUsernameRequest( InputPeerChannel(channel_id=newChannelID, access_hash=newChannelAccessHash), desiredPublicUsername)) inGrab = False await e.edit("__Grab Riuscito!__") else: await asyncio.sleep(1) except: await asyncio.sleep(1)
async def create_new_channel( self, channel_name, channel_desc, public=False, publicName=None, ): createdPrivateChannel = await self.client( CreateChannelRequest(channel_name, channel_desc, megagroup=False)) # if you want to make it public use the rest if public: newChannelID = createdPrivateChannel.__dict__["chats"][0].__dict__[ "id"] newChannelAccessHash = createdPrivateChannel.__dict__["chats"][ 0].__dict__["access_hash"] desiredPublicUsername = publicName checkUsernameResult = await self.client( CheckUsernameRequest( InputPeerChannel(channel_id=newChannelID, access_hash=newChannelAccessHash), desiredPublicUsername)) if (checkUsernameResult == True): try: await self.client( UpdateUsernameRequest( InputPeerChannel(channel_id=newChannelID, access_hash=newChannelAccessHash), desiredPublicUsername)) return 0, "Public channel created successfully!" except errors.rpcerrorlist.UsernameOccupiedError: return 1, "Username is already taken by someone else!" return 99, "Could not make the channel public..." return 0, "Private channel created successfully!"
async def _(e): type_of_group = e.pattern_match.group(1) group_name = e.pattern_match.group(2) username = None if " ; " in group_name: group_ = group_name.split(" ; ", maxsplit=1) group_name = group_[0] username = group_[1] xx = await eor(e, get_string("com_1")) if type_of_group == "b": try: r = await e.client( CreateChatRequest( users=["@missrose_bot"], title=group_name, ), ) created_chat_id = r.chats[0].id await e.client( DeleteChatUserRequest( chat_id=created_chat_id, user_id="@missrose_bot", ), ) result = await e.client( ExportChatInviteRequest(peer=created_chat_id, ), ) await xx.edit( get_string("chats_4").format(group_name, result.link), link_preview=False, ) except Exception as ex: await xx.edit(str(ex)) elif type_of_group in ["g", "c"]: try: r = await e.client( CreateChannelRequest( title=group_name, about=get_string("chats_5"), megagroup=type_of_group != "c", )) created_chat_id = r.chats[0].id if username: await e.client(UpdateUsernameRequest(created_chat_id, username)) result = "https://t.me/" + username else: result = (await e.client( ExportChatInviteRequest(peer=created_chat_id, ), )).link await xx.edit( get_string("chats_6").format(f"[{group_name}]({result})"), link_preview=False, ) except Exception as ex: await xx.edit(str(ex))
async def _(e): type_of_group = e.pattern_match.group(1) group_name = e.pattern_match.group(2) username = None if " ; " in group_name: group_ = group_name.split(" ; ", maxsplit=1) group_name = group_[0] username = group_[1] xx = await eor(e, "`Processing...`") if type_of_group == "b": try: r = await e.client( CreateChatRequest( users=["@missrose_bot"], title=group_name, ), ) created_chat_id = r.chats[0].id await e.client( DeleteChatUserRequest( chat_id=created_chat_id, user_id="@missrose_bot", ), ) result = await e.client( ExportChatInviteRequest(peer=created_chat_id, ), ) await xx.edit( f"Your [{group_name}]({result.link}) Group Made Boss!", link_preview=False, ) except Exception as ex: await xx.edit(str(ex)) elif type_of_group in ["g", "c"]: try: r = await e.client( CreateChannelRequest( title=group_name, about="Join @TeamUltroid", megagroup=type_of_group != "c", )) created_chat_id = r.chats[0].id if username: await e.client(UpdateUsernameRequest(created_chat_id, username)) result = "https://t.me/" + username else: result = (await e.client( ExportChatInviteRequest(peer=created_chat_id, ), )).link await xx.edit( f"Your [{group_name}]({result}) Group/Channel Has been made Boss!", link_preview=False, ) except Exception as ex: await xx.edit(str(ex))
async def change_profile_username(event): username = event.pattern_match.group(1) chat = await event.get_chat() if not chat.admin_rights or not chat.creator: await client.update_message( event, "`Chat admin privileges are required to do that`") return if "@" in username: username = username[1:] allowed_char = re.match(r"[a-zA-Z][\w\d]{3,30}[a-zA-Z\d]", username) if not allowed_char: await client.update_message(event, "`Invalid Username`") elif len(username) > 30: await client.update_message(event, "`Channel username is too long.`") elif len(username) < 5: await client.update_message(event, "`Channel username is too short`") else: try: await client(UpdateUsernameRequest(chat.id, username)) await client.update_message( event, "`Succesfully changed channel username`") except Exception as exc: if isinstance(exc, errors.AdminsTooMuchError): await client.update_message( event, "`You're admin of too many public channels, make some channels private to change the username of this channel.`" ) if isinstance(exc, errors.UsernameOccupiedError): await client.update_message(event, f"`{username} is already taken`") if isinstance(exc, errors.ChatNotModifiedError): await client.update_message( event, "`The chat or channel wasn't modified`")
from telethon.tl.functions.channels import CreateChannelRequest, CheckUsernameRequest, UpdateUsernameRequest from telethon.tl.types import InputChannel, InputPeerChannel createdPrivateChannel = client(CreateChannelRequest("title","about",megagroup=False)) #if you want to make it public use the rest newChannelID = createdPrivateChannel.__dict__["chats"][0].__dict__["id"] newChannelAccessHash = createdPrivateChannel.__dict__["chats"][0].__dict__["access_hash"] desiredPublicUsername = "******" checkUsernameResult = client(CheckUsernameRequest(InputPeerChannel(channel_id=newChannelID, access_hash=newChannelAccessHash), desiredPublicUsername)) if(checkUsernameResult==True): publicChannel = client(UpdateUsernameRequest(InputPeerChannel(channel_id=newChannelID, access_hash=newChannelAccessHash), desiredPublicUsername))