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

typings: make channelId non-nullable on MessageComponentInteraction #6600

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/structures/MessageComponentInteraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ class MessageComponentInteraction extends Interaction {
constructor(client, data) {
super(client, data);

/**
* The id of the channel this interaction was sent in
* @type {Snowflake}
* @name MessageComponentInteraction#channelId
*/

/**
* The message to which the component was attached
* @type {Message|APIMessage}
Expand Down
1 change: 1 addition & 0 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1318,6 +1318,7 @@ export class MessageComponentInteraction extends Interaction {
public readonly component: MessageActionRowComponent | Exclude<APIMessageComponent, APIActionRowComponent> | null;
public componentType: Exclude<MessageComponentType, 'ACTION_ROW'>;
public customId: string;
public channelId: Snowflake;
public deferred: boolean;
public ephemeral: boolean | null;
public message: Message | APIMessage;
Expand Down
9 changes: 9 additions & 0 deletions typings/tests.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { APIInteractionGuildMember } from 'discord-api-types';
import {
ApplicationCommand,
ApplicationCommandChoicesData,
Expand Down Expand Up @@ -560,6 +561,10 @@ client.on('messageCreate', message => {
});

client.on('interaction', async interaction => {
assertType<Snowflake | null>(interaction.guildId);
assertType<Snowflake | null>(interaction.channelId);
assertType<GuildMember | APIInteractionGuildMember | null>(interaction.member);

if (!interaction.isCommand()) return;

void new MessageActionRow();
Expand All @@ -578,6 +583,10 @@ client.on('interaction', async interaction => {

// @ts-expect-error
await interaction.reply({ content: 'Hi!', components: [button] });

if (interaction.isMessageComponent()) {
assertType<Snowflake>(interaction.channelId);
}
});

client.login('absolutely-valid-token');
Expand Down