Hellp guys i tried to make a Telegram bot but when i try to run it its give me this error in line 3 :
Exception has occurred: ImportError
cannot import name 'Filters' from 'telegram.ext' (C:\Users\Mustafa\AppData\Local\Programs\Python\Python311\Lib\site-packages\telegram\ext\__init__.py)
File "C:\Users\Mustafa\Desktop\Telegram bot\my_telegram_bot.py", line 3, in <module>
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, CallbackContext
ImportError: cannot import name 'Filters' from 'telegram.ext' (C:\Users\Mustafa\AppData\Local\Programs\Python\Python311\Lib\site-packages\telegram\ext\__init__.py)
i used 2 packages pytube and python_telegram_bot , also i have the latest version of everything idk where is the wrong .
The code :
import os
from telegram import Update
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, CallbackContext
from pytube import YouTube
def start(update: Update, context: CallbackContext) -> None:
update.message.reply_text('Send me a YouTube link with /download to get the video.')
def download_video(update: Update, context: CallbackContext) -> None:
url = context.args[0]
yt = YouTube(url)
video = yt.streams.get_highest_resolution()
video.download()
filename = f"{yt.title}.mp4"
os.rename(video.default_filename, filename)
update.message.reply_document(document=open(filename, 'rb'))
os.remove(filename)
def main() -> None:
# Replace 'YOUR_API_TOKEN' with your actual API token
updater = Updater(token='MY telegram token', use_context=True)
dispatcher = updater.dispatcher
dispatcher.add_handler(CommandHandler('start', start))
dispatcher.add_handler(CommandHandler('download', download_video, pass_args=True))
dispatcher.add_handler(MessageHandler(Filters.text & ~Filters.command, start))
updater.start_polling()
updater.idle()
if __name__ == '__main__':
main()