today i'm struggling to edit a discord channel topic in a loop. By that I mean that it sometimes works sometimes don't, and it gets really strange. The code :
@tasks.loop(seconds=5)
async def prixcrypto():
channel = client.get_channel(776053500059975690)
databtc = requests.get('https://api.binance.com/api/v1/ticker/24hr?symbol=BTCUSDT') #Get bitcoin/usdt actual price and information over a 24h period
jdata = databtc.json()
datavet = requests.get('https://api.binance.com/api/v1/ticker/24hr?symbol=VETUSDT').json() #same for vet/usdt
#Here I print the data I want (symbol of crypto, price, priceChangePercent(24h,%), priceChange(24h,$)
print(f'{datavet["symbol"]} : {format(float(datavet["bidPrice"]),".6f")} / 24H : {datavet["priceChangePercent"]}% / 24H : {format(float(datavet["priceChange"]), ".2f")}$')
print(f'{jdata["symbol"]} : {format(float(jdata["bidPrice"]),".2f")} / 24H : {jdata["priceChangePercent"]}% / 24H : {format(float(jdata["priceChange"]), ".2f")}$')
#Here I send to the channel the string with values
phrase = (f'{jdata["symbol"]} : {format(float(jdata["bidPrice"]),".2f")} / 24H : {jdata["priceChangePercent"]}% / 24H : {format(float(jdata["priceChange"]), ".2f")}$ || {datavet["symbol"]} : {format(float(datavet["bidPrice"]),".6f")} / 24H : {datavet["priceChangePercent"]}% / 24H : {format(float(datavet["priceChange"]), ".6f")}$')
await channel.edit(topic=phrase)
@prixcrypto.before_loop #Initiate the loop when client is ready
async def before_prixcrypto():
await client.wait_until_ready()
prixcrypto.start()
The result is something like this :
Cmd :
VETUSDT : 0.017466 / 24H : 8.205% / 24H : 0.00$
BTCUSDT : 19360.00 / 24H : 2.869% / 24H : 540.00$
Discord Topic :
BTCUSDT : 19360.00 / 24H : 2.869% / 24H : 540.00$ || VETUSDT : 0.017466 / 24H : 8.205% / 24H : 0.00$
What I want to happen : I start the program, and then it prints the results, then it should change the topic and it loops every 5 seconds.
What it does : I start the program, it prints the results on cmd, then it doesn't change the topic, and sometime later it will get back into the function, print the results, change the topic, start again 5 seconds later, print the results, and won't change topic, and it will do that again sometime later. So it's really strange.
It's very strange, and from what I "found", because I'm not sure, it bugs at the "await channel.edit()" line. I tried to change loop time but it doesn't seem to change anything, I verified it's not a problem with binance API requests limit, I searched on google and found nothing interesting so I don't know.
Your help is welcome, thanks for reading me.
Just to say I started programming 3 months ago and didn't really learn to code in python, i'm just finding what I need to make my ideas real and then do what I need, at my university we learn C. I'm french.