Skip to content

Extract bot name from a command #2145

Answered by vehlwn
vehlwn asked this question in Q&A
Discussion options

You must be logged in to vote

I managed to make a temporary solution but I want this to be a built in feature.

import telebot.async_telebot
import telebot.asyncio_filters

bot = telebot.async_telebot.AsyncTeleBot(TOKEN)

class MatchBotUsernameFilter(telebot.asyncio_filters.SimpleCustomFilter):
    key = "match_bot_username"

    def __init__(self, bot_name: str) -> None:
        super().__init__()
        self.bot_name = bot_name

    async def check(self, message: telebot.types.Message) -> bool:
        text = message.text or ""
        words = text.split(maxsplit=1)
        full_command = words[0].split("@")
        if len(full_command) >= 2:
            bot_username = full_command[1]
            return bot_username ==

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by vehlwn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant
Converted from issue

This discussion was converted from issue #2144 on January 28, 2024 07:55.