Skip to content

Commit 40c760f

Browse files
Added MessageEmbed#isEmpty and fixed MessageAction not allowing to send embeds with just an image set
1 parent ac5b652 commit 40c760f

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

src/main/java/net/dv8tion/jda/core/entities/MessageEmbed.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
import java.awt.Color;
2626
import java.time.OffsetDateTime;
2727
import java.time.format.DateTimeFormatter;
28-
import java.util.*;
28+
import java.util.Collections;
29+
import java.util.List;
30+
import java.util.Objects;
2931

3032
/**
3133
* Represents an embed displayed by Discord.
@@ -281,6 +283,18 @@ public OffsetDateTime getTimestamp()
281283
return timestamp;
282284
}
283285

286+
/**
287+
* Whether this embed is empty.
288+
*
289+
* @return True, if this embed has no content
290+
*/
291+
public boolean isEmpty()
292+
{
293+
return getLength() == 0
294+
&& getImage() == null
295+
&& getThumbnail() == null;
296+
}
297+
284298
/**
285299
* The total amount of characters that is displayed when this embed is displayed by the Discord client.
286300
*
@@ -344,6 +358,8 @@ public boolean isSendable(AccountType type)
344358
{
345359
Checks.notNull(type, "AccountType");
346360
final int length = getLength();
361+
if (isEmpty())
362+
return false;
347363

348364
switch (type)
349365
{

src/main/java/net/dv8tion/jda/core/requests/restaction/MessageAction.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ public MessageAction(JDA api, Route.CompiledRoute route, MessageChannel channel,
103103
public boolean isEmpty()
104104
{
105105
return Helpers.isBlank(content)
106-
&& (!hasPermission(Permission.MESSAGE_EMBED_LINKS)
107-
|| embed == null || embed.getLength() == 0);
106+
&& (embed == null || embed.isEmpty() || !hasPermission(Permission.MESSAGE_EMBED_LINKS));
108107
}
109108

110109
/**
@@ -248,7 +247,7 @@ public MessageAction embed(final MessageEmbed embed)
248247
{
249248
final AccountType type = getJDA().getAccountType();
250249
Checks.check(embed.isSendable(type),
251-
"Provided Message contains an embed with a length greater than %d characters, which is the max for %s accounts!",
250+
"Provided Message contains an empty embed or an embed with a length greater than %d characters, which is the max for %s accounts!",
252251
type == AccountType.BOT ? MessageEmbed.EMBED_MAX_LENGTH_BOT : MessageEmbed.EMBED_MAX_LENGTH_CLIENT, type);
253252
}
254253
this.embed = embed;

src/main/java/net/dv8tion/jda/webhook/WebhookMessageBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public WebhookMessageBuilder addEmbeds(MessageEmbed... embeds)
124124
{
125125
Checks.notNull(embed, "Embed");
126126
Checks.check(embed.isSendable(AccountType.BOT),
127-
"One of the provided embeds exceeds the maximum character count of %d!", MessageEmbed.EMBED_MAX_LENGTH_BOT);
127+
"One of the provided embeds is empty or exceeds the maximum character count of %d!", MessageEmbed.EMBED_MAX_LENGTH_BOT);
128128
this.embeds.add(embed);
129129
}
130130
return this;
@@ -152,7 +152,7 @@ public WebhookMessageBuilder addEmbeds(Collection<MessageEmbed> embeds)
152152
{
153153
Checks.notNull(embed, "Embed");
154154
Checks.check(embed.isSendable(AccountType.BOT),
155-
"One of the provided embeds exceeds the maximum character count of %d!", MessageEmbed.EMBED_MAX_LENGTH_BOT);
155+
"One of the provided embeds is empty or exceeds the maximum character count of %d!", MessageEmbed.EMBED_MAX_LENGTH_BOT);
156156
this.embeds.add(embed);
157157
}
158158
return this;

0 commit comments

Comments
 (0)