feat: add content to `Message` repr
Signed-off-by: HedTB
Summary
It's a very simple change to include the message content in Message's repr. I don't see why this wouldn't be shown, as its purpose is to give information on the message.
May be the most minor change I could've done but it's a neat change :)
Checklist
- [x] If code changes were made, then they have been tested
- [ ] I have updated the documentation to reflect the changes
- [x] I have formatted the code properly by running
task lint - [x] I have type-checked the code by running
task pyright
- [ ] This PR fixes an issue
- [x] This PR adds something new (e.g. new method or parameters)
- [ ] This PR is a breaking change (e.g. methods or parameters removed/renamed)
- [ ] This PR is not a code change (e.g. documentation, README, ...)
I don't think it's such a good idea, if someone doesn't have the message_content intent enabled on both discord developer portal and Bot object instantiation, he may mistakenly think that the messages that he's receiving have None as content, when in fact they don't receive them because the intent is missing.
I don't think it's such a good idea, if someone doesn't have the
message_contentintent enabled on both discord developer portal and Bot object instantiation, he may mistakenly think that the messages that he's receiving haveNoneas content, when in fact they don't receive them because the intent is missing.
They would be just as confused if they'd print Message.content, as that'd be None. Don't see the issue.
I don't think it's such a good idea, if someone doesn't have the
message_contentintent enabled on both discord developer portal and Bot object instantiation, he may mistakenly think that the messages that he's receiving haveNoneas content, when in fact they don't receive them because the intent is missing.
Oops, didn't see that comment before writing mine.
Without the intent, message content is empty (i.e. ""), so this shouldn't be an issue. If it were None somehow, there'd still be the differentiation between a literal None and a "None" string when using !r.
Seems good. Truncating the message content at some limit (e.g. 200 chars) might be a good addition, since message content can be up to 4000 characters in length.
Could you also add a changelog entry?
Imagine if someone tried to print a list of disnake.Message object, wouldn't their repr output be too long?
@onerandomusername Thoughts on truncating and/or moving the content field in the repr? I think I'd prefer to keep it limited to some degree, Message reprs are already fairly long.
@onerandomusername Thoughts on truncating and/or moving the content field in the repr? I think I'd prefer to keep it limited to some degree,
Messagereprs are already fairly long.
I'm not entirely a fan of having the content in the repr at all. It can potentionally be 4000 characters long, which is way too much when debugging, and not really relevant when looking at the repr of the message itself (if the content is needed it can be printing separately)
OTOH I understand it could be useful to show some of the content, at least with the private intent change.
Perhaps at the end of the repr and truncated to the first 25 and last 25 characters (if longer than 50-ish characters)
What's the status of this PR?
I agree with @onerandomusername . Message content in repr should be either truncated or not added at all, since one could explicitly print it when needed.
Truncating the message content sounds like a good idea, I'll edit my code 👍