Skip to content
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

Message.channel is a DMChannel in on_message for an ephemeral message not sent as a DM #7370

Open
3 tasks done
Harmon758 opened this issue Aug 12, 2021 · 1 comment · Fixed by DisnakeDev/disnake#197
Open
3 tasks done
Labels
bug This is a bug with the library. discord limitation This can't be fixed because it's a discord limitation

Comments

@Harmon758
Copy link
Contributor

Harmon758 commented Aug 12, 2021

Summary

When an ephemeral message is sent, the resulting Message object dispatched to on_message has a channel attribute that is an instance of DMChannel, even if the ephemeral message was not sent as a Direct Message.

Reproduction Steps

  • Send an ephemeral message (not as a DM, e.g. in a text channel)
  • Check type(message.channel) for the corresponding message in on_message

Expected Results

message.channel should be the proper type (e.g. TextChannel), rather than DMChannel.

Actual Results

message.channel is a DMChannel.

Intents

N/A

System Information

  • Python v3.9.5-final
  • discord.py v2.0.0-alpha
    • discord.py pkg_resources: v2.0.0a3469+g1e17b7fc
  • aiohttp v3.7.4.post0
  • system info: Windows 10 10.0.19042

Checklist

  • I have searched the open issues for duplicates.
  • I have shown the entire traceback, if possible.
  • I have removed my token from display, if visible.

Additional Context

This seems to be because Discord's API does not provide guild_id for ephemeral messages for the Message Create event.

When discord.py receives the event, ConnectionState.parse_message_create assigns the channel with ConnectionState._get_guild_channel:

discord.py/discord/state.py

Lines 509 to 511 in 1e17b7f

def parse_message_create(self, data):
channel, _ = self._get_guild_channel(data)
message = Message(channel=channel, data=data, state=self)

When the data doesn't have guild_id, ConnectionState._get_guild_channel returns a DMChannel:

discord.py/discord/state.py

Lines 403 to 413 in 1e17b7f

def _get_guild_channel(self, data):
channel_id = int(data['channel_id'])
try:
guild = self._get_guild(int(data['guild_id']))
except KeyError:
channel = DMChannel._from_message(self, channel_id)
guild = None
else:
channel = guild and guild._resolve_channel(channel_id)
return channel or PartialMessageable(state=self, id=channel_id), guild

@Harmon758 Harmon758 added the unconfirmed bug A bug report that needs triaging label Aug 12, 2021
@Rapptz Rapptz added bug This is a bug with the library. discord limitation This can't be fixed because it's a discord limitation and removed unconfirmed bug A bug report that needs triaging labels Aug 12, 2021
@Rapptz
Copy link
Owner

Rapptz commented Aug 12, 2021

Since guild_id isn't provided then the alternative here would be doing an O(n) search for the guild channels to see which one matched which doesn't seem like a good idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This is a bug with the library. discord limitation This can't be fixed because it's a discord limitation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants