Lyrics Command In Discord.py
So I was trying to make a lyrics command using the lyrics ovh api in discord.py and I'm getting this error : 'An error occurred: Command raised an exception: KeyError: 'lyrics'' im
Solution 1:
If lyrics
not in your json
object then python will raise KeyError
. If you want to avoid from this, you can use get
method.
data = {
"key1": "value1",
"key2": "value2"
}
value1 = data["key1"] #no error
value2 = data.get("key2") #no error
value3 = data["key3"] #this will raise KeyError because key3 not in data
value3 = data.get("key3") #this will not raise any error and return default value
value3 = data.get("key3", "No lyrics could be found.") #we passed the default value so this will return
#"No lyrics could be found" if key3 is not exist in json
Post a Comment for "Lyrics Command In Discord.py"