1

https://user-images.githubusercontent.com/20538090/160258926-405804cc-dad7-42ce-8dc1-e92bba7acb1e.png

Before switching to async telebot, I wrote eval and exec commands, so I could manage the bot from telegram, but I can't use it after doing async, could you please help?

My eval & exec code

if msg.startswith("/eval "):
    command = msg.replace("/eval ","")
    Do = eval(command)
    if Do != None:
        bot.send_message(chat_id,str(Do))
        return
    elif msg.startswith("/exec "):
        command = msg.replace("/exec ","").strip()
        command = command.replace("bsm(", "bot.send_message(chat_id,")

        exec(command)
    return

Before async: https://user-images.githubusercontent.com/20538090/160259071-011fe294-b4c8-41bd-9b9e-662885195bbb.png

After async: https://user-images.githubusercontent.com/20538090/160259040-c0af13c2-6064-46d6-b379-ccdf8bfc79d8.png (No answer)

Dark
  • 25
  • 4

1 Answers1

1

The information you are looking for is detailed in the documentation.

GitHub page

Use

from telebot.async_telebot import AsyncTeleBot
import telebot

bot = AsyncTeleBot('TOKEN')

@bot.message_handler(text_startswith="/eval")
async def start(message):
    pass

bot.add_custom_filter(telebot.asyncio_filters.TextStartsFilter())

bot.polling()
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 29 '22 at 20:15
  • but this command doesn't do anything, the problem is we need to run asynchronous stuff inside eval or exec, like bot sending messages inside for – Dark Mar 29 '22 at 20:30