Вчера все работало стабильно, сегодня переустановил винду и встретил такую ошибку: ImportError: cannot import name 'telegram' from 'telebot'
помогите ее решить пожалуйста, вот мой код если надо:
import telebot
import telegram
import random
from telebot import types
import sqlite3
from sqlite3 import Error
from time import ctime
bot = telebot.TeleBot('Тут токен')
img = open('C:\\Users\\User\\Desktop\\bot\\D.gif', 'rb')
W = open("C:\\Users\\User\\Desktop\\bot\\Welcome.gif", 'rb')
f = open('C:\\Users\\User\\Desktop\\bot\\fact(ru).txt', 'r', encoding='UTF-8')
facts = f.read().split('\n')
f.close()
f = open('C:\\Users\\User\\Desktop\\bot\\fact(en).txt', 'r', encoding='UTF-8')
thinks = f.read().split('\n')
f.close()
def post_sql_query(sql_query):
with sqlite3.connect('C:\\Users\\User\\Downloads\\Telegram Desktop\\baza.db') as connection:
cursor = connection.cursor()
try:
cursor.execute(sql_query)
except Error:
pass
result = cursor.fetchall()
return result
def register_user(user, username, first_name, last_name):
user_check_query = f'SELECT * FROM USERS WHERE user_id = {user};'
user_check_data = post_sql_query(user_check_query)
if not user_check_data:
insert_to_db_query = f'INSERT INTO USERS (user_id, username, first_name, last_name) VALUES ({user}, "{username}", "{first_name}", "{last_name}", "{ctime()}");'
post_sql_query(insert_to_db_query )
def user_exists(self, user_id):
if self.get_user_name(user_id) is None:
return False
return True
def start(m, res=False):
register_user(m.from_user.id, m.from_user.username, m.from_user.first_name, m.from_user.last_name)
conn = sqlite3.connect('C:\\Users\\User\\Desktop\\bot\\baza.db', check_same_thread=False)
cursor = conn.cursor()
def db_table_val(user_id: int, user_name: str, first_name: str, last_name):
cursor.execute('INSERT INTO users (user_id, username, first_name, last_name) VALUES (?,?,?,?)', (user_id, user_name, first_name, last_name))
conn.commit()
def get_user_name(self, user_id):
result = self.cursor.execute('SELECT name FROM users WHERE id = ?', (user_id,)).fetchone()
if result is None:
return None
return result[0]
def mmm(m):
us_id = m.from_user.id
us_name = m.from_user.username
firstname = m.from_user.first_name
lastname = m.from_user.last_name
db_table_val(user_id=us_id, username=us_name, first_name=firstname, last_name=lastname)
conn.commit()
@bot.message_handler(commands=['start'])
def get_text_messages(m):
markup=types.ReplyKeyboardMarkup(resize_keyboard=True)
item1=types.KeyboardButton("Русский ")
item2=types.KeyboardButton('English ')
markup.add(item1)
markup.add(item2)
bot.send_message(m.chat.id, 'Select language:', reply_markup=markup)
@bot.message_handler(content_types=["text"])
def aga (m, res=True):
if m.text.strip() == 'Русский ' :
markup=types.ReplyKeyboardMarkup(resize_keyboard=False)
item1=types.KeyboardButton("Факт")
item2=types.KeyboardButton("Профиль")
markup.add(item1)
markup.add(item2)
bot.send_video(m.chat.id, img, None, 'Text')
bot.send_message(m.chat.id, f'Добро пожаловать {m.from_user.first_name}', reply_markup=markup)
bot.send_message(m.chat.id, 'Нажми: \nФакт - для получения интересного факта\nПрофиль - для просмотра профиля', parse_mode=telegram.ParseMode.MARKDOWN, reply_markup=markup )
if m.text.strip() == 'Факт' :
answer = random.choice(facts)
bot.send_message(m.chat.id, answer)
if m.text.strip() == 'Профиль' :
bot.send_message(m.chat.id, f'=====Ваш профиль=====\n\nИмя: `{m.from_user.first_name}`\nАйди: `{m.from_user.id}`', parse_mode=telegram.ParseMode.MARKDOWN)
elif m.text.strip() == 'English ' :
markup = types.ReplyKeyboardMarkup(resize_keyboard=False)
item1 = types.KeyboardButton('Fact')
item2 = types.KeyboardButton('Profile')
markup.add(item1)
markup.add(item2)
bot.send_video(m.chat.id, W, None, 'Text')
bot.send_message(m.chat.id, f'Welcome `{m.from_user.first_name}`', parse_mode=telegram.ParseMode.MARKDOWN, reply_markup=markup)
bot.send_message(m.chat.id, 'Click:\nFact - to get an interesting fact\n Profile - to view the profile', reply_markup=markup)
elif m.text.strip() == 'Fact' :
answer = random.choice(thinks)
bot.send_message(m.chat.id, answer)
elif m.text.strip() == 'Profile' :
bot.send_message(m.chat.id, f'=====Your profile=====\n\nName: `{m.from_user.first_name}`\nID: `{m.from_user.id}`', parse_mode=telegram.ParseMode.MARKDOWN)
bot.delete_webhook()
bot.polling(none_stop=True, timeout=123)
<code>