Reputation: 13
Hello i have a problem with my discord bot. I'm new to python and also very new to creating my own bot, and I couldn't find an answer to my problem. Iam running a discord bot that checks the availability of stocks on a specific web site. And when i use a "While true: ... time.sleep(60)" loop to refresh and download the data from the web site my bot just shows offline on a discord server. I tried to change the timer to longer and also tried to print and send some messages to a discord. And i found out that even when the bot is offline it can send message and everything. No errors or any warning everything works but the bot is offline. If there is somebody who could help me out with my problem or heard about it. I would appreciate it a lot. I can share the code if there is somebody who has a little bit of time to help me.
Code:
while True:
Zoznam.clear()
hodnoty = nacitaniehodnot()
produkt = hodnoty[0]
obrazok = hodnoty[1]
pocetpoloziek = hodnoty[2]
shopy = ''
cennik = ''
for i in Zoznam:
shopy = shopy+i[0]+'\n'
cennik = cennik+i[1]+'\n'
embed = discord.Embed(title =produkt,color= 0x008FFF)
embed.set_thumbnail(url=obrazok)
embed.set_author(name='Heureka', url=url,icon_url="https://i1.wp.com/blog.heureka.sk/wp-content/uploads/2019/12/cropped-lupa_heureka_rgb-01.png?fit=512%2C512&ssl=1&w=640")
embed.add_field(name="Obchod", value=shopy, inline=True)
embed.add_field(name="Cena", value=cennik, inline=True)
#embed.add_field(name="Doprava", value=doprava, inline=True)
global sprava
if pocetpoloziek != y and sprava is not None:
await sprava.delete()
sprava = await channel.send(embed=embed)
i=y
elif not sprava:
sprava = await channel.send(embed=embed)
time.sleep(30)
Upvotes: 1
Views: 819
Reputation: 819
The problem is likely due to time.sleep
since time.sleep
is not asynchronous and will block all commands during the sleep time.
Try importing asyncio import asyncio
and using await asyncio.sleep(30)
instead since it won't block other commands from running during the sleep time.
Upvotes: 2