I am trying to execute this code on Google Colab but It takes forever to be done and nothing appears to be working on the bot so when I check the updates of the telelgram bot There is no response. the Token code is correct.
!pip install telebot
import random
import telebot
from telebot import types
bot = telebot.TeleBot('API_Token')
@bot.message_handler(commands=['generate'])
def generate_string(message):
chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
generated_string = ''.join(random.choice(chars) for _ in range(16))
link = f"{generated_string}"
user_id = bot.get_updates()[-1].message.chat.id
bot.send_message(user_id, link)
@bot.message_handler(commands=['stop'])
def stop_bot(message):
user_id = bot.get_updates()[-1].message.chat.id
bot.send_message(user_id, "Type 'yes' to stop the bot.")
bot.register_next_step_handler(message, stop_bot_handler)
def stop_bot_handler(message):
user_id = bot.get_updates()[-1].message.chat.id
if message.text.lower() == 'yes':
bot.send_message(user_id, "Bot stopped.")
bot.stop_polling()
else:
bot.send_message(user_id, "Type 'yes' to stop the bot.")
bot.register_next_step_handler(message, stop_bot_handler)
if __name__ == '__main__':
bot.polling()