Why am I getting this error with Asyncio?
I'm getting this error after my code runs for a few minutes: future: <Task finished name='Task-1' coro=<timer() done, defined at c:\Users(my name)\Desktop\DiscordBot\roblox test copy.py:12> exception=KeyError('data')> I'm pretty new to python so I can't get this to work. Any help would be appreciated.
Here is my code:
from time import sleep
from discord.ext import commands
import datetime
import asyncio
import requests
import json
import time
bot = commands.Bot(command_prefix='!')
async def timer():
await bot.wait_until_ready()
channel = bot.get_channel(my discord channel, not sending in case it can be traced to my server)
msg_sent = False
while True:
r = requests.get('https://badges.roblox.com/v1/users/2642375267/badges?limit=10&sortOrder=Desc')
badgedata = r.json()['data']
risetimes = []
for d in badgedata:
badgeid = d['id']
risetimes.append(badgeid)
firstThing = risetimes[0]
times = []
for rt in risetimes:
eztime = (str(rt))
times.append(eztime)
xd = requests.get('https://badges.roblox.com/v1/users/2642375267/badges/awarded-dates?badgeIds=' + str(firstThing))
badgegaineddata = xd.json()['data']
badgegainedtime = []
for ig in badgegaineddata:
badgegaineduwu = ig['awardedDate']
badgegainedtime.append(badgegaineduwu)
firstElement = badgegainedtime[0]
date_string = str(firstElement)
Thedatetime = date_string
date_string = date_string[:26]
date_format = datetime.datetime.strptime(date_string, "%Y-%m-%dT%H:%M:%S.%f")
unix_time = datetime.datetime.timestamp(date_format)
unix_time = unix_time - 18000
dt = datetime.datetime.fromtimestamp(unix_time)
currentunixtime = time.time()
if unix_time > currentunixtime -3:
await channel.send("https://www.roblox.com/badges/" + str(firstThing))
await channel.send(dt)
msg_sent = True
sleep(3)
await asyncio.sleep(1)
bot.loop.create_task(timer())
bot.run('token')
How many English words
do you know?
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
how many words do you know
Powered by Examplum