Search code examples
pythontelegrampython-telegram-bot

Create Topic on Telegram groups


Using python there's a way to create Topics on Telegram? I'm trying to find something about this but I don't find anything, probably I'm just not looking on the right place, I was doing something like this but obviously not longer works:

import telegram
import asyncio

async def create_topic():
    bot = telegram.Bot(token="XXXX000000XXXXX")

    chat = await bot.get_chat(chat_id=-0000000)

    topic_name = "My New Topic"

    # Create the topic
    result = chat.create_topic(topic_name)

    # Check if the topic was created successfully
    if result:
        print("Topic created successfully!")
    else:
        print("Failed to create topic.")
    
asyncio.run(create_topic())

Anybody have any Idea of how make topics? or it's not longer possible


Solution

  • I guess you are looking for the method Chat.create_forum_topic. The full list of available API methods related to forums topics can be found in the official Telegram Bot API docs and you can find the corresponding PTB counterparts in the docs of the Bot class.


    Disclaimer: I'm currently the maintainer of python-telegram-bot.