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

Support sending multiple embeds #1239

Merged
merged 7 commits into from
Jul 13, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ declare namespace Eris {
type AdvancedMessageContent = {
allowedMentions?: AllowedMentions;
content?: string;
/** @deprecated */
embed?: EmbedOptions;
embeds?: EmbedOptions[];
flags?: number;
messageReference?: MessageReferenceReply;
/** @deprecated */
Expand Down
18 changes: 12 additions & 6 deletions lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ class Client extends EventEmitter {
* @arg {Boolean} [content.allowedMentions.repliedUser] Whether or not to mention the author of the message being replied to.
* @arg {String} content.content A content string
* @arg {Object} [content.embed] An embed object. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/channel#embed-object) for object structure
reinacchi marked this conversation as resolved.
Show resolved Hide resolved
* @arg {Array<Object>} [content.embeds] An array of embed objects. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/channel#embed-object) for object structure
* @arg {Object} [content.messageReference] The message reference, used when replying to messages
* @arg {String} [content.messageReference.channelID] The channel ID of the referenced message
* @arg {Boolean} [content.messageReference.failIfNotExists=true] Whether to throw an error if the message reference doesn't exist. If false, and the referenced message doesn't exist, the message is created without a referenced message
Expand All @@ -601,8 +602,10 @@ class Client extends EventEmitter {
};
} else if(content.content !== undefined && typeof content.content !== "string") {
content.content = "" + content.content;
} else if(content.content === undefined && !content.embed && !file) {
return Promise.reject(new Error("No content, file, or embed"));
} else if(content.content === undefined && !content.embed && !content.embeds && !file) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should probably check if embeds length is above 0.

reinacchi marked this conversation as resolved.
Show resolved Hide resolved
return Promise.reject(new Error("No content, file, or embeds"));
} else if(content.embed) {
bsian03 marked this conversation as resolved.
Show resolved Hide resolved
this.emit("warn", "[DEPRECATED] content.embed is deprecated. Use content.embeds instead");
}
content.allowed_mentions = this._formatAllowedMentions(content.allowedMentions);
if(content.messageReference) {
Expand All @@ -628,7 +631,7 @@ class Client extends EventEmitter {
content.message_reference = {message_id: content.messageReferenceID};
}
} else if(!file) {
return Promise.reject(new Error("No content, file, or embed"));
return Promise.reject(new Error("No content, file, or embeds"));
}
return this.requestHandler.request("POST", Endpoints.CHANNEL_MESSAGES(channelID), true, content, file).then((message) => new Message(message, this));
}
Expand Down Expand Up @@ -1223,6 +1226,7 @@ class Client extends EventEmitter {
* @arg {Boolean | Array<String>} [content.allowedMentions.users] Whether or not to allow all user mentions, or an array of specific user mentions to allow.
* @arg {String} content.content A content string
* @arg {Object} [content.embed] An embed object. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/channel#embed-object) for object structure
* @arg {Array<Object>} [content.embeds] An array of embed objects. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/channel#embed-object) for object structure
* @arg {Number} [content.flags] A number representing the flags to apply to the message. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/channel#message-object-message-flags) for flags reference
* @returns {Promise<Message>}
*/
Expand All @@ -1234,10 +1238,12 @@ class Client extends EventEmitter {
};
} else if(content.content !== undefined && typeof content.content !== "string") {
content.content = "" + content.content;
} else if(content.content === undefined && !content.embed && content.flags === undefined) {
return Promise.reject(new Error("No content, embed or flags"));
} else if(content.content === undefined && !content.embed && !content.embeds && content.flags === undefined) {
return Promise.reject(new Error("No content, embeds or flags"));
} else if(content.embed) {
this.emit("warn", "[DEPRECATED] content.embed is deprecated. Use content.embeds instead");
}
if(content.content !== undefined || content.embed || content.allowedMentions) {
if(content.content !== undefined || content.embeds || content.allowedMentions) {
content.allowed_mentions = this._formatAllowedMentions(content.allowedMentions);
}
}
Expand Down
2 changes: 2 additions & 0 deletions lib/structures/PrivateChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class PrivateChannel extends Channel {
* @arg {Boolean} [options.allowedMentions.repliedUser] Whether or not to mention the author of the message being replied to
* @arg {String} content.content A content string
* @arg {Object} [content.embed] An embed object. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/channel#embed-object) for object structure
* @arg {Array<Object>} [content.embeds] An array of embed objects. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/channel#embed-object) for object structure
* @arg {Object} [content.messageReference] The message reference, used when replying to messages
* @arg {String} [content.messageReference.channelID] The channel ID of the referenced message
* @arg {Boolean} [content.messageReference.failIfNotExists=true] Whether to throw an error if the message reference doesn't exist. If false, and the referenced message doesn't exist, the message is created without a referenced message
Expand Down Expand Up @@ -85,6 +86,7 @@ class PrivateChannel extends Channel {
* @arg {String} content.content A content string
* @arg {Boolean} [content.disableEveryone] Whether to filter @everyone/@here or not (overrides default)
* @arg {Object} [content.embed] An embed object. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/channel#embed-object) for object structure
* @arg {Array<Object>} [content.embeds] An array of embed objects. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/channel#embed-object) for object structure
* @arg {Number} [content.flags] A number representing the flags to apply to the message. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/channel#message-object-message-flags) for flags reference
* @returns {Promise<Message>}
*/
Expand Down
2 changes: 2 additions & 0 deletions lib/structures/TextChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class TextChannel extends GuildChannel {
* @arg {Boolean} [options.allowedMentions.repliedUser] Whether or not to mention the author of the message being replied to
* @arg {String} content.content A content string
* @arg {Object} [content.embed] An embed object. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/channel#embed-object) for object structure
* @arg {Array<Object>} [content.embeds] An array of embed objects. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/channel#embed-object) for object structure
* @arg {Object} [content.messageReference] The message reference, used when replying to messages
* @arg {String} [content.messageReference.channelID] The channel ID of the referenced message
* @arg {Boolean} [content.messageReference.failIfNotExists=true] Whether to throw an error if the message reference doesn't exist. If false, and the referenced message doesn't exist, the message is created without a referenced message
Expand Down Expand Up @@ -128,6 +129,7 @@ class TextChannel extends GuildChannel {
* @arg {String} content.content A content string
* @arg {Boolean} [content.disableEveryone] Whether to filter @everyone/@here or not (overrides default)
* @arg {Object} [content.embed] An embed object. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/channel#embed-object) for object structure
* @arg {Array<Object>} [content.embeds] An array of embed objects. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/channel#embed-object) for object structure
* @arg {Number} [content.flags] A number representing the flags to apply to the message. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/channel#message-object-message-flags) for flags reference
* @returns {Promise<Message>}
*/
Expand Down