discord.ext.commands.bot: Ignoring exception in command subs Traceback

Viewed 37

Hello I was trying to create a Discord bot with YT API where I can write a username of an YT channel and return me the number of subs but I receive an error.

Here is the code:

async def subscriptores(ctx,username):
    data = urllib.request.urlopen("https://www.googleapis.com/youtube/v3/channels?part=statistics&forUsername=" + username + "&key=" + KEY).read()
    subs = json.loads(data)["items"][0]["statistics"]["subscriberCount"]
    response = username + " tiene " + "{:,d}".format(int(subs)) + " suscriptores!"
    await ctx.send(response)

and the Error

[ERROR   ] discord.ext.commands.bot: Ignoring exception in command subs
Traceback (most recent call last):
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line 190, in wrapped
    ret = await coro(*args, **kwargs)
  File "c:\Users\User\Documents\sx\bot py\Scripts\main.py", line 21, in subscriptores
    subs = json.loads(data)["items"][0]["statistics"]["subscriberCount"]
KeyError: 'items'
0 Answers
Related