Skip to content

Commit

Permalink
feat: add support for modals
Browse files Browse the repository at this point in the history
  • Loading branch information
suneettipirneni committed Feb 10, 2022
1 parent eecf09a commit c929e07
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/discord.js/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ exports.Collector = require('./structures/interfaces/Collector');
exports.CommandInteractionOptionResolver = require('./structures/CommandInteractionOptionResolver');
exports.ContextMenuCommandInteraction = require('./structures/ContextMenuCommandInteraction');
exports.DMChannel = require('./structures/DMChannel');
exports.Embed = require('@discordjs/builders').Embed;
exports.Embed = require('./structures/Embed');
exports.UnsafeEmbed = require('@discordjs/builders').UnsafeEmbed;
exports.Emoji = require('./structures/Emoji').Emoji;
exports.Guild = require('./structures/Guild').Guild;
Expand Down
5 changes: 4 additions & 1 deletion packages/discord.js/src/structures/MessagePayload.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const { MessageFlags } = require('discord-api-types/v9');
const { RangeError } = require('../errors');
const Components = require('../util/Components');
const DataResolver = require('../util/DataResolver');
const Embeds = require('../util/Embeds');
const MessageFlagsBitField = require('../util/MessageFlagsBitField');
const Util = require('../util/Util');

Expand Down Expand Up @@ -193,7 +194,9 @@ class MessagePayload {
content,
tts,
nonce,
embeds: this.options.embeds?.map(embed => (embed instanceof Embed ? embed : new Embed(embed)).toJSON()),
embeds: this.options.embeds?.map(embed =>
embed instanceof Embed ? embed.toJSON() : Embeds.transformJSON(embed),
),
components,
username,
avatar_url: avatarURL,
Expand Down
37 changes: 35 additions & 2 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
channelMention,
codeBlock,
Component,
Embed,
Embed as BuildersEmbed,
formatEmoji,
hideLinkEmbed,
hyperlink,
Expand Down Expand Up @@ -89,6 +89,7 @@ import {
GatewayIntentBits,
ActivityFlags,
APIMessageComponentEmoji,
EmbedType,
} from 'discord-api-types/v9';
import { ChildProcess } from 'node:child_process';
import { EventEmitter } from 'node:events';
Expand Down Expand Up @@ -472,6 +473,34 @@ export class SelectMenuComponent extends BuilderSelectMenuComponent {
public constructor(data?: SelectMenuComponentData | APISelectMenuComponent);
}

export interface EmbedData {
title?: string;
type?: EmbedType;
description?: string;
url?: string;
timestamp?: string;
color?: number;
footer?: EmbedFooterData;
image?: EmbedImageData;
thumbnail?: EmbedImageData;
provider?: EmbedProviderData;
author?: EmbedAuthorData;
fields?: EmbedFieldData[];
}

export interface EmbedImageData {
url?: string;
}

export interface EmbedProviderData {
name?: string;
url?: string;
}

export class Embed extends BuildersEmbed {
public constructor(data?: EmbedData | APIEmbed);
}

export interface MappedChannelCategoryTypes {
[ChannelType.GuildNews]: NewsChannel;
[ChannelType.GuildVoice]: VoiceChannel;
Expand Down Expand Up @@ -2381,6 +2410,11 @@ export class Components extends null {
public static transformJSON(data: ComponentData | APIMessageComponent): APIMessageComponent;
}

export class Embeds extends null {
private constructor();
public static transformJSON(data: EmbedData | APIEmbed): APIEmbed;
}

export class VoiceChannel extends BaseGuildVoiceChannel {
public readonly speakable: boolean;
public type: ChannelType.GuildVoice;
Expand Down Expand Up @@ -5193,7 +5227,6 @@ export {
SelectMenuOption,
UnsafeSelectMenuOption,
ActionRowComponent,
Embed,
UnsafeEmbed,
} from '@discordjs/builders';
export { DiscordAPIError, HTTPError, RateLimitError } from '@discordjs/rest';

0 comments on commit c929e07

Please sign in to comment.