Skip to content

fix: Message.system_content() error with application_command message type #2825

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

BOXERRMD
Copy link

@BOXERRMD BOXERRMD commented Jul 7, 2025

Message.system_content(...):

add one condition to check if the message is an application_command. Return basic message.

Summary

The purpose of this pull request is to correct a problem with the system_content function in the Message class. This function is supposed to return a string, but when an application_command is detected, it returns None because it was not processed.

Information

  • This PR fixes an issue.
  • 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, typehinting,
    examples, ...).

Checklist

  • I have searched the open pull requests for duplicates.
  • If code changes were made then they have been tested.
    • I have updated the documentation to reflect the changes.
  • If type: ignore comments were used, a comment is also left explaining why.
  • I have updated the changelog to include these changes.

BOXERRMD added 2 commits July 7, 2025 15:58
### Message.system_content(...):

add one condition to check if the message is an application_command. Return basic message.
@BOXERRMD BOXERRMD requested a review from a team as a code owner July 7, 2025 14:23
@pullapprove4 pullapprove4 bot requested a review from plun1331 July 7, 2025 14:23
@BOXERRMD BOXERRMD changed the title Fix bugs Fix bug : Message.system_content() error with application_command message type Jul 7, 2025
@BOXERRMD BOXERRMD changed the title Fix bug : Message.system_content() error with application_command message type fix: Message.system_content() error with application_command message type Jul 7, 2025
Comment on lines +1596 to +1600
if self.type is MessageType.application_command:
return (
f"{self.author.name} sent an application command to {self.channel.name} channel in"
f" {self.guild.name if self.guild is not None else 'NoneGuild'} guild."
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

system_content shows the rendered content on the client for certain message types, the client does not render it like this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah.. See below:

Image

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see what the problem is... Is it the message that the function returns that's the problem?

Copy link
Contributor

@DA-344 DA-344 Jul 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, system_content shows, as I said, the content rendered in the client side. Application_command messages are just bot messages to respond to interactions, there is no actual system_content apart from the "user used command"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I got that, thanks for the clarification. But there's still a problem: if we use it to get the ForwadedMessage and the bot picks up the message from a bot, the function returns None when it should have returned a string as indicated in the typing

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forwarded messages have their own content, and the info provided by discord is pretty limited, could you detail more?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function is supposed to return the content according to the type of message required. For all those that are private, such as calls, they're not, and that's normal, given that you can't call a bot. But for application commands, if we use Message.system_content() it will return None because it doesn't handle the case of a message from a bot responding to an interaction.
As for the snapshots attribute, it does exist, but the version it's based on is not yet available (unless you use the main branch without going through version 2.6.1). So the only way to get snapshots is to use system_content(). That's why I wanted to deal with the application_command case, to avoid any more bugs. But if I need to change the message, I can replace it with self.content, which corresponds to an empty string.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since here, from my understanding, the only thing that could fit as system content would be {username} used {command}, AND it is not currently possible to obtain the associated command's name, I am unsure how any attempt at this could work. @DA-344 Can you confirm I am not misunderstanding something here ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently, they want to obtain the contents of a application command response in a message snapshot, but for that, we wouldn't use system_content. And no, you are not misunderstanding anything as far as I understand what this PR is meant to "solve".

So the only way to get snapshots is to use system_content(). That's why I wanted to deal with the application_command case, to avoid any more bugs. But if I need to change the message, I can replace it with self.content, which corresponds to an empty string.

No, system_content should not be used to get message snapshots content, just wait until the release that includes Message.snapshots is released (or use the master branch).

Comment on lines +1596 to +1600
if self.type is MessageType.application_command:
return (
f"{self.author.name} sent an application command to {self.channel.name} channel in"
f" {self.guild.name if self.guild is not None else 'NoneGuild'} guild."
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah.. See below:

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants