disnake icon indicating copy to clipboard operation
disnake copied to clipboard

feat: add content to `Message` repr

Open HedTB opened this issue 3 years ago • 11 comments

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, ...)

HedTB avatar Dec 02 '22 14:12 HedTB

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.

Snipy7374 avatar Dec 02 '22 15:12 Snipy7374

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.

They would be just as confused if they'd print Message.content, as that'd be None. Don't see the issue.

HedTB avatar Dec 02 '22 16:12 HedTB

Could you also add a changelog entry?

Will do once I'm home.

HedTB avatar Dec 02 '22 16:12 HedTB

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.

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.

shiftinv avatar Dec 02 '22 16:12 shiftinv

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?

Snipy7374 avatar Dec 02 '22 16:12 Snipy7374

Could you also add a changelog entry?

I did it, sorry for the delay.

HedTB avatar Dec 06 '22 14:12 HedTB

@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.

shiftinv avatar Dec 14 '22 17:12 shiftinv

@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.

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)

onerandomusername avatar Dec 16 '22 07:12 onerandomusername

What's the status of this PR?

shiftinv avatar Feb 02 '23 15:02 shiftinv

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.

EQUENOS avatar Mar 08 '23 07:03 EQUENOS

Truncating the message content sounds like a good idea, I'll edit my code 👍

HedTB avatar Mar 08 '23 20:03 HedTB