Closed ThorntonMatthewD closed 2 years ago
This isn't a bug with discord.py. Our classes are not designed to be user constructable, which includes discord.Message
.
Your error is that you're providing None
where an actual json payload is expected, with certain mandatory keys. You'll need to mock a minimal acceptable version of this payload.
As this is not a bug with the library, you're more than welcome to join the official help server and talk about this more there.
Is this a payload received by Discord or is it a synthetic payload you made? The library doesn't support creating instances of the classes by hand.
Thank you both for your responses! This is a synthetic payload being generated by a library used for helping with creating mocks for use with dpy bots in pytest. Since a required parameter being missing is not a scenario that would occur outside of meddling like my own in this case then I retract this issue. Thank you for your help! :)
FWIW you can omit the key instead of giving it a value of None.
FWIW you can omit the key instead of giving it a value of None.
Thank you so much! I've just given this a shot, and it's working like a charm now. One more issue down! 🥳
Summary
Upon instantiating an instance of the Message class, if the value of
application
is None within the MessagePayload the constructor receives, it will cause a TypeError to be thrown whenever an instance of MessageApplication is later created.Reproduction Steps
I am attempting to port a testing library over to being compatible with the upcoming v2.0 release. I don't have all of the "plumbing" in place yet, however I did come across the following scenario:
I instantiate an instance of discord.Message without providing an instance of MessageApplication to the constructor. There exists within my MessagePayload a key named
application
with a value ofNone
. This is placed into a localapplication
variable here: https://github.com/Rapptz/discord.py/blob/1aaa32d4bced65d346f0634984c95a707bf0c00b/discord/message.py#L1516Below, whenever an instance of MessageApplication is created, this None value is passed in as the data param: https://github.com/Rapptz/discord.py/blob/1aaa32d4bced65d346f0634984c95a707bf0c00b/discord/message.py#L1520
In the constructor for MessageApplication, any
data['...']
call will throw the following error:TypeError: 'NoneType' object is not subscriptable
https://github.com/Rapptz/discord.py/blob/1aaa32d4bced65d346f0634984c95a707bf0c00b/discord/message.py#L634
Minimal Reproducible Code
No response
Expected Results
I'm not entirely sure what the best tactic would be here to mitigate this, but I guess I'd expect a check for if
application == None
before proceeding with creating the MessageApplication object.Actual Results
I received the following exception:
TypeError: 'NoneType' object is not subscriptable
The full pytest exception traceback:
This is the MessagePayload that causes the error to occur:
Intents
messages=True, guilds=True, members=True, reactions=True, message_content=True
System Information
Checklist
Additional Context
I am experiencing this issue while running pytest and also while utilizing the dpytest library to help facilitate writing a test for a command, so it's a bit of an odd situation.