discord.py icon indicating copy to clipboard operation
discord.py copied to clipboard

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

Open Harmon758 opened this issue 4 years ago • 1 comments

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

  • [X] I have searched the open issues for duplicates.
  • [X] I have shown the entire traceback, if possible.
  • [X] 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: https://github.com/Rapptz/discord.py/blob/1e17b7fceaf7173b1666465e639d1bebaa126683/discord/state.py#L509-L511

When the data doesn't have guild_id, ConnectionState._get_guild_channel returns a DMChannel: https://github.com/Rapptz/discord.py/blob/1e17b7fceaf7173b1666465e639d1bebaa126683/discord/state.py#L403-L413

Harmon758 avatar Aug 12 '21 13:08 Harmon758

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.

Rapptz avatar Aug 12 '21 14:08 Rapptz