I'm trying to make a discord bot and I've added functionality of the tasks repeating after 24 hours using tasks.loop
after at an interval of 24 hours( 64800 seconds). Since the code is run on repl.it, I've used uptimerobot to continuously send a ping after 5 minutes to make it running always in the repl.it. My issue is that even after checking history in the channel the message is getting sent again as you can see in the below image. ( by checking here I mean the explanation which is the explanation that comes with the API). I'm using NASA api here.
def get_APOD():
image = requests.get("https://api.nasa.gov/planetary/apod?api_key="+apod)
json_data = json.loads(image.text)
description = json_data["url"]
explanation = "'" + json_data["explanation"]+ "'"
title = json_data["title"]
return description,explanation,title
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
send_message.start()
@tasks.loop(seconds=64800.0)
async def send_message():
channel = client.get_channel(int(apod_channel))
messages = await channel.history(limit=1).flatten()
description,explanation,title = get_APOD()
if messages[0].content == explanation:
print("Its the same")
else:
await channel.send(description)
await channel.send(title)
await channel.send(explanation)
Here you can see the messages repeating twice. It shouldn't by the code I've written here. Since it checks for the history in the channel.
However when I restart the repl.it IDE the code will run alright and print "It's the same" as it should if the message is already sent but otherwise it's failing.
What is the issue here? Appreciate any help.