Skip to content

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

Open
DisnakeDev/disnake
#197
@Harmon758

Description

@Harmon758

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis is a bug with the library.discord limitationThis can't be fixed because it's a discord limitation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions