v5.1.2 | Message Forwarding and Voice Messages
Overview
This release adds support for new message features.
Forwarding messages (#2744)
You can now handle forwarded messages using the new message snapshots.
@Override
public void onMessageReceived(MessageReceivedEvent event) {
MessageReference messageReference = event.getMessage().getMessageReference();
// Forwarded messages have a reference of type FORWARD
if (messageReference != null && messageReference.getType() == MessageReference.MessageReferenceType.FORWARD) {
// The content of the forwarded message is provided as a snapshot
MessageSnapshot snapshot = event.getMessage().getMessageSnapshots().getFirst();
System.out.println("Received forwarded message with content: " + snapshot.getContentRaw());
}
}
A bot can also forward a message using Message#fowardTo
. Note that a forwarded message cannot contain any additional content.
Voice messages (#2738)
You can now send voice messages with JDA, by utilizing the new FileUpload#asVoiceMessage
method on your audio attachments.
channel.sendFiles(
FileUpload.fromData(audioFile)
.asVoiceMessage(MediaType.parse("audio/ogg"), waveform, 10.5) // 10.5 seconds audio/ogg message
).queue();
To create a voice message, you must first determine the audio media type of your voice message and sample a waveform up to 256 bytes. Voice messages require a valid audio/*
media type like audio/ogg
.
The waveform is used to render the voice message shape in the preview. It must not be an accurate sampling of the actual audio.
New Features
- Add support for message forwarding by @MinnDevelopment in #2744
- Support sending voice messages by @MinnDevelopment in #2738
Bug Fixes
Full Changelog: v5.1.1...v5.1.2
Installation
Gradle
repositories {
mavenCentral()
}
dependencies {
implementation("net.dv8tion:JDA:5.1.2")
}
Maven
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>5.1.2</version>
</dependency>