tao mot bot de tai nhac tu thu muc tren dropbox len telegram
- User
tao mot bot de tai nhac tu thu muc tren dropbox len telegram
- Assistant
- User
ban co the viet mot dong code hoan chinh de toi copy khong
- Assistant
Tất nhiên, đây là một đoạn mã hoàn chỉnh để bạn có thể sao chép và chạy:
from telegram import Update from telegram.ext import Updater, CommandHandler, CallbackContext import dropbox TELEGRAM_TOKEN = 'YOUR_TELEGRAM_BOT_TOKEN' DROPBOX_ACCESS_TOKEN = 'YOUR_DROPBOX_ACCESS_TOKEN' dbx = dropbox.Dropbox(DROPBOX_ACCESS_TOKEN) def start(update: Update, context: CallbackContext) -> None: update.message.reply_text('Chào! Tôi là bot tải nhạc từ Dropbox lên Telegram. Gõ /upload để tải nhạc.') def upload(update: Update, context: CallbackContext) -> None: music_folder = '/path/to/music/folder' # Đổi thư mục này thành thư mục của bạn try: files = dbx.files_list_folder(music_folder) for entry in files.entries: metadata, res = dbx.files_download(entry.path_lower) update.message.reply_audio(audio=res.content, filename=metadata.name) except Exception as e: update.message.reply_text('Có lỗi xảy ra: ' + str(e)) def main(): updater = Updater(TELEGRAM_TOKEN, use_context=True) dispatcher = updater.dispatcher dispatcher.add_handler(CommandHandler("start", start)) dispatcher.add_handler(CommandHandler("upload", upload)) updater.start_polling() updater.idle() if __name__ == '__main__': main()