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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Action): Ensure all properties on getChannel() are passed #10278

Merged
merged 2 commits into from
May 16, 2024

Conversation

Jiralite
Copy link
Member

@Jiralite Jiralite commented May 15, 2024

Please describe the changes this PR makes and why it should be merged:
User-installable applications are in the wild, and this is one problem I have noticed so far, despite not being exactly relevant.

When a command is invoked in a group direct message channel and the channel partial is enabled, discord.js will proceed to create a channel (as direct message channels not initially cached). This is an example payload:

{
  type: 3,
  owner_id: 'user_id',
  name: '馃挍馃挏馃枻',
  last_pin_timestamp: '2023-06-26T16:59:39+00:00',
  last_message_id: 'message_id',
  id: 'id',
  icon: null,
  flags: 0
}

Notice type is 3. discord.js results in this channel:

DMChannel {
  type: 1,
  flags: ChannelFlagsBitField { bitfield: 0 },
  id: 'id',
  recipientId: undefined,
  lastMessageId: 'message_id',
  lastPinTimestamp: null,
  messages: DMMessageManager { channel: [Circular *1] }
}

type has been modified to 1! It's a DMChannel now!

The reason this happens is because of the way getChannel() works:

getChannel(data) {
const payloadData = {};
const id = data.channel_id ?? data.id;
if ('recipients' in data) {
payloadData.recipients = data.recipients;
} else {
// Try to resolve the recipient, but do not add the client user.
const recipient = data.author ?? data.user ?? { id: data.user_id };
if (recipient.id !== this.client.user.id) payloadData.recipients = [recipient];
}
if (id !== undefined) payloadData.id = id;
if ('guild_id' in data) payloadData.guild_id = data.guild_id;
if ('last_message_id' in data) payloadData.last_message_id = data.last_message_id;
return (
data[this.client.actions.injectedChannel] ??
this.getPayload(payloadData, this.client.channels, id, Partials.Channel)
);
}

We are only extracting properties from data and sending them off as payloadData. This is an example resulting payload:

{
  recipients: [ { id: undefined } ],
  id: 'id',
  last_message_id: 'message_id'
}

We are losing properties here, most notably, type. Merging our overriding properties alongside the original data allows a PartialGroupDMChannel to be created.

Status and versioning classification:

  • Code changes have been tested against the Discord API, or there are no code changes
  • I know how to update typings and have done so, or typings don't need updating

Copy link

vercel bot commented May 15, 2024

The latest updates on your projects. Learn more about Vercel for Git 鈫楋笌

2 Ignored Deployments
Name Status Preview Comments Updated (UTC)
discord-js 猬滐笍 Ignored (Inspect) Visit Preview May 15, 2024 6:36pm
discord-js-guide 猬滐笍 Ignored (Inspect) Visit Preview May 15, 2024 6:36pm

@Jiralite Jiralite added this to the discord.js 14.15.3 milestone May 15, 2024
@kodiakhq kodiakhq bot merged commit 92c1a51 into main May 16, 2024
7 checks passed
@kodiakhq kodiakhq bot deleted the fix/action-channel branch May 16, 2024 07:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

4 participants