Skip to content

Commit

Permalink
fix(APIMessage): don't send embeds for non-webhook requests
Browse files Browse the repository at this point in the history
  • Loading branch information
vladfrangu committed May 29, 2021
1 parent 6339ac1 commit 361f338
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/rest/DiscordAPIError.js
Expand Up @@ -40,7 +40,7 @@ class DiscordAPIError extends Error {
* @type {HTTPErrorData}
*/
this.requestData = {
jsonData: request.options.data,
json: request.options.data,
files: request.options.files ?? [],
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/rest/HTTPError.js
Expand Up @@ -35,7 +35,7 @@ class HTTPError extends Error {
/**
* The HTTP data that was sent to Discord
* @typedef {Object} HTTPErrorData
* @property {*} jsonData The JSON data that was sent
* @property {*} json The JSON data that was sent
* @property {HTTPAttachmentData[]} files The files that were sent with this request, if any
*/

Expand All @@ -51,7 +51,7 @@ class HTTPError extends Error {
* @type {HTTPErrorData}
*/
this.requestData = {
jsonData: request.options.data,
json: request.options.data,
files: request.options.files ?? [],
};
}
Expand Down
7 changes: 4 additions & 3 deletions src/structures/APIMessage.js
Expand Up @@ -125,6 +125,7 @@ class APIMessage {
*/
resolveData() {
if (this.data) return this;
const isWebhook = this.isWebhook;

const content = this.makeContent();
const tts = Boolean(this.options.tts);
Expand All @@ -139,7 +140,7 @@ class APIMessage {
}

const embedLikes = [];
if (this.isInteraction || this.isWebhook) {
if (this.isInteraction || isWebhook) {
if (this.options.embeds) {
embedLikes.push(...this.options.embeds);
}
Expand All @@ -150,7 +151,7 @@ class APIMessage {

let username;
let avatarURL;
if (this.isWebhook) {
if (isWebhook) {
username = this.options.username || this.target.name;
if (this.options.avatarURL) avatarURL = this.options.avatarURL;
}
Expand Down Expand Up @@ -192,7 +193,7 @@ class APIMessage {
tts,
nonce,
embed: this.options.embed === null ? null : embeds[0],
embeds,
embeds: isWebhook ? embeds : undefined,
username,
avatar_url: avatarURL,
allowed_mentions:
Expand Down

0 comments on commit 361f338

Please sign in to comment.