From 443961ce43bc37dbe8705e42a28afcfaf8e94a7d Mon Sep 17 00:00:00 2001 From: Isabella Date: Sun, 10 Dec 2017 14:22:59 -0600 Subject: [PATCH] fix(CreateMessage): fix attachment and array sending (#2158) --- src/structures/shared/CreateMessage.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/structures/shared/CreateMessage.js b/src/structures/shared/CreateMessage.js index 5abf0799e..8ae2c369f 100644 --- a/src/structures/shared/CreateMessage.js +++ b/src/structures/shared/CreateMessage.js @@ -19,9 +19,22 @@ module.exports = async function createMessage(channel, options) { if (isNaN(options.nonce) || options.nonce < 0) throw new RangeError('MESSAGE_NONCE_TYPE'); } + let { content } = options; if (options instanceof MessageEmbed) options = webhook ? { embeds: [options] } : { embed: options }; if (options instanceof MessageAttachment) options = { files: [options.file] }; + if (content instanceof Array || options instanceof Array) { + const which = content instanceof Array ? content : options; + const attachments = which.filter(item => item instanceof MessageAttachment); + const embeds = which.filter(item => item instanceof MessageEmbed); + if (attachments.length) options = { files: attachments }; + if (embeds.length) options = { embeds }; + if ((embeds.length || attachments.length) && content instanceof Array) { + content = null; + options.content = ''; + } + } + if (options.reply && !(channel instanceof User || channel instanceof GuildMember) && channel.type !== 'dm') { const id = channel.client.users.resolveID(options.reply); const mention = `<@${options.reply instanceof GuildMember && options.reply.nickname ? '!' : ''}${id}>`; @@ -29,8 +42,8 @@ module.exports = async function createMessage(channel, options) { options.content = `${mention}${typeof options.content !== 'undefined' ? `, ${options.content}` : ''}`; } - if (options.content) { - options.content = Util.resolveString(options.content); + if (content) { + options.content = Util.resolveString(content); if (options.split && typeof options.split !== 'object') options.split = {}; // Wrap everything in a code block if (typeof options.code !== 'undefined' && (typeof options.code !== 'boolean' || options.code === true)) {