skip to Main Content
`@loader.tds
class testr(loader.Module):
    '''name'''
    strings = {
        "name": "test",   
    }
    async def client_ready(self, client, db):
        self.test_channel, _ = await utils.asset_channel(
            self._client,
            "Test - chat",
            "check descr",
            silent=True,
            archive=True,
            _folder="m",
            
        )   
        await self.client(functions.channels.InviteToChannelRequest(self.test_channel, ['@my_bot']))
           
        await self.client(functions.channels.EditAdminRequest(
                channel=self.test_channel,
                user_id="@my_bot",
                admin_rights=ChatAdminRights(ban_users=True, post_messages=True, edit_messages=True),
                rank="xTest",
            )
        )

    def __init__(self):`

I’m trying to create a group and topics in it using a user bot on a teletone. I can’t find anywhere in the documentation how to properly work with topics. I only figured out how to write messages in a certain topic. But I can’t figure out how to create it and find out the topic id.
Here is a pre-launch code that successfully creates a group and invites the necessary users to it

2

Answers


  1. What is telethon…?
    I’m trying to create a group and topics in it using a user bot on a teletone. I can’t find anywhere in the documentation how to properly work with topics. I only figured out how to write messages in a certain topic. But I can’t figure out how to create it and find out the topic id. Here is a pre-launch code that successfully creates a group and invites the necessary users to it

    Login or Signup to reply.
  2. You can create a forum using CreateChannelRequest

    Create a topic using CreateForumTopicRequest

    from telethon import TelegramClient
    from telethon.tl.functions.channels import CreateChannelRequest, CreateForumTopicRequest
    import asyncio
    
    client = TelegramClient(...)
    
    async def main():
        # Creating a forum:
        forum = await client(CreateChannelRequest(
            title = 'FORUM_NAME',
            about = 'ABOUT',
            forum = True
        ))
        forum_id = forum.updates[1].channel_id
    
        # Creating a topic:
        topic = await client(CreateForumTopicRequest(
            channel = forum_id,
            title = 'TOPIC_NAME'
        ))
        topic_id = topic.updates[0].id
    
        # Send a message to the topic
        await client.send_message(
            entity = topic_id,
            message = 'MESSAGE_TEXT',
            reply_to = topic.updates[0].id
        )
    
    if __name__ == '__main__':
        client.start()
        loop = asyncio.get_event_loop()
        loop.run_until_complete(main())
    

    You can also convert an existing group into a forum using ToggleForumRequest

    from telethon.tl.functions.channels import ToggleForumRequest
    
    await client(ToggleForumRequest(
        channel = YOUR_GROUP,
        enabled = True
    )
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search