-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
36 lines (29 loc) · 832 Bytes
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import spotify
import telebot
import time
#Add token here
TOKEN = ''
def bot_init():
bot = telebot.TeleBot(token=TOKEN)
@bot.message_handler(commands=['start'])
def send_welcome(message):
user = message.from_user
user_id = user.id
bot.reply_to(
message, 'Welcome to SpotifyBot! New tracks will be sent to you when added to the Spotify library.')
while True:
urls, tracks_id = spotify.fetch()
if len(urls) > 0:
for url in urls:
bot.send_message(user_id, url)
spotify.add_to_tracklist(tracks_id)
time.sleep(20)
print('Starting SpotifyBot....\n')
print('SpotifyBot Started!')
bot.polling()
try:
while True:
bot_init()
except:
time.sleep(20)
bot_init()