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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ These changes are available on the `master` branch, but have not yet been releas

### Fixed

- Fixed `Message.system_content()` raised an error if the message is an
application_command ([#2825](https://github.com/Pycord-Development/pycord/pull/2825))
- Fixed `Enum` options not setting the correct type when only one choice is available.
([#2577](https://github.com/Pycord-Development/pycord/pull/2577))
- Fixed `codec` option for `FFmpegOpusAudio` class to make it in line with
Expand Down
6 changes: 6 additions & 0 deletions discord/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -1593,6 +1593,12 @@ def system_content(self) -> str:
" build the server!"
)

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."
)
Comment on lines +1596 to +1600
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
Member

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
Member

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


async def delete(
self, *, delay: float | None = None, reason: str | None = None
) -> None:
Expand Down
Loading