Package net.dv8tion.jda.webhook
Class WebhookMessage
- java.lang.Object
-
- net.dv8tion.jda.webhook.WebhookMessage
-
public class WebhookMessage extends java.lang.Object
A special Message that can only be sent to aWebhookClient
.
This message provides special attributes calledusername
andavatar_url
which override the default username and avatar of a Webhook message.This message can send multiple embeds at once!
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static WebhookMessage
embeds(java.util.Collection<MessageEmbed> embeds)
Creates a new WebhookMessage instance with the providedMessageEmbeds
static WebhookMessage
embeds(MessageEmbed first, MessageEmbed... embeds)
Creates a new WebhookMessage instance with the providedMessageEmbeds
static WebhookMessage
files(java.lang.String name1, java.lang.Object data1, java.lang.Object... attachments)
Constructs a message around pairs of (Name, Data).static WebhookMessage
files(java.util.Map<java.lang.String,?> attachments)
Constructs a message around pairs of (Name, Data).static WebhookMessage
from(Message message)
Creates a new WebhookMessage instance with the providedMessage
as layout for copying.boolean
isFile()
Whether this message contains an attachment
-
-
-
Method Detail
-
embeds
public static WebhookMessage embeds(MessageEmbed first, MessageEmbed... embeds)
Creates a new WebhookMessage instance with the providedMessageEmbeds
- Parameters:
first
- The first embed to use for this messageembeds
- The other embeds to use for this message- Returns:
- The resulting WebhookMessage instance
- Throws:
java.lang.IllegalArgumentException
- If any of the provided embeds isnull
or exceeds the maximum total character count ofMessageEmbed.EMBED_MAX_LENGTH_BOT
-
embeds
public static WebhookMessage embeds(java.util.Collection<MessageEmbed> embeds)
Creates a new WebhookMessage instance with the providedMessageEmbeds
- Parameters:
embeds
- The embeds to use for this message- Returns:
- The resulting WebhookMessage instance
- Throws:
java.lang.IllegalArgumentException
- If any of the provided embeds isnull
or exceeds the maximum total character count ofMessageEmbed.EMBED_MAX_LENGTH_BOT
-
files
public static WebhookMessage files(java.util.Map<java.lang.String,?> attachments)
Constructs a message around pairs of (Name, Data).
You can add up to 10 attachments to one message.
The supported data types areInputStream
,File
, andbyte[]
.Example
Map<String, Object> map = new HashMap<>(); map.put("dog", new File("dog.png")); map.put("cat", new URL("https://random.cat/meow").openStream()); map.put("bird", new byte[100]); WebhookMessage message = WebhookMessage.files(map);
- Parameters:
attachments
- Map containing pairs from file names to data streams- Returns:
- WebhookMessage for the provided files
- Throws:
java.lang.IllegalArgumentException
- If one of the provided files is not readable or the provided map is null/empty- See Also:
WebhookMessageBuilder.addFile(String, InputStream)
,WebhookMessageBuilder.addFile(String, byte[])
,WebhookMessageBuilder.addFile(String, File)
,WebhookMessageBuilder.addFile(File)
-
files
public static WebhookMessage files(java.lang.String name1, java.lang.Object data1, java.lang.Object... attachments)
Constructs a message around pairs of (Name, Data).
You can add up to 10 attachments to one message. This means you can have up to 20 arguments.
The supported data types areInputStream
,File
, andbyte[]
.Example
WebhookMessage message = WebhookMessage.files( "dog", new File("dog.png"), "cat", new URL("https://random.cat/meow").openStream(), "bird", new byte[100] );
- Parameters:
name1
- The first name argumentdata1
- The first data argumentattachments
- Additional pairs in the form of (Name, Data)- Returns:
- WebhookMessage for the provided files
- Throws:
java.lang.IllegalArgumentException
- If the provided arguments are not pairs of (Name, Data) or if one of the provided files is not readable- See Also:
WebhookMessageBuilder.addFile(String, InputStream)
,WebhookMessageBuilder.addFile(String, byte[])
,WebhookMessageBuilder.addFile(String, File)
,WebhookMessageBuilder.addFile(File)
-
from
public static WebhookMessage from(Message message)
Creates a new WebhookMessage instance with the providedMessage
as layout for copying.
This does not copy the attachments of the provided message!- Parameters:
message
- The message to copy- Returns:
- The resulting WebhookMessage instance
- Throws:
java.lang.IllegalArgumentException
- If the provided message isnull
-
isFile
public boolean isFile()
Whether this message contains an attachment- Returns:
- True, if this message contains an attachment
-
-