The Error:
Ignoring exception in on_message
Traceback (most recent call last):
File “…”, line 34 3, in _run_event
await coro(*args, **kwargs)
File “main.py”, line 56, in _on_message
options = options + db[“encouragements”]
TypeError: can only concatenate list (not “ObservedList”) to list
tbh I didn´t get why the > thing is in line 35, maybe someone can help me explaining it.
Thanks for help
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.
The thing is, nobody here has memorized the video or the code used there.
Also the problem is NOT in line 35, but in line 56.
Because you use imported libraries, the error message will usually point to several points where the error is happening because it’s happening in the code within the imported library. So it points there, but also to where the error actually occured and with several connected libraries the message can end up pointing to half a dozen different lines → so you need to look at entire message focusing on File “main.py” or however you main file is called.
Now with that being said, the error also points to options = options + db[“encouragements”].
So that’s the code where the error is happening and this might be line 56. This can be very confusing when starting out but it’s actually super helpful as it gives insight in where the error is happening in different files/libraries. So if you would have happened to write those yourself or in a team, you can track down all the connected files with the error-message directly.
Now given db is an imported object, it’s values might be a special kind of list, hence addition doesn’t work. You might be able to .append() the list instead of using “+” or might need to turn db[“…”] into a list.
Maybe print the value of db and check the type for further info.
I used the .append keyword with options but it didn’t work.
Adding .value to the same statement of options = options + db[“encouragements”] worked for me.
Modify the line to be
options = options + db[“encouragements”].value
To understand why .value, print both ‘options’ and ‘db[“encouragements”]’ in the for loop. Through this you will be able to see that db[“encouragements”] is like a dictionary which has value=["//Your message"]