-
Is there any way to filter messages by bot tag like PS: I think it's more of a bug than discussion because teloxide in Rust and telegraf in NodeJS do have bot name parsing enabled in commands out of the box. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
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 == self.bot_name
return True
@bot.message_handler(commands=["help"], match_bot_username=True)
async def start_message(message):
await bot.reply_to(message, "Show this message")
async def main():
me = await bot.get_me()
if me.username is None:
raise RuntimeError("Bot must have username")
bot_name = me.username
bot.add_custom_filter(MatchBotUsernameFilter(bot_name))
await bot.infinity_polling()
if __name__ == "__main__":
asyncio.run(main()) |
Beta Was this translation helpful? Give feedback.
I managed to make a temporary solution but I want this to be a built in feature.