@@ -14,6 +14,7 @@ import net.dv8tion.jda.api.events.message.MessageReceivedEvent
1414import net.dv8tion.jda.api.requests.RestAction
1515import net.dv8tion.jda.api.utils.FileUpload
1616import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder
17+ import net.dv8tion.jda.api.utils.messages.MessageCreateData
1718import java.util.regex.Pattern
1819
1920class MessageContext (
@@ -66,13 +67,25 @@ class MessageContext(
6667 send0({ setEmbeds(EmbedBuilder ().apply (embed).build()) }).submit()
6768 }
6869
70+ /* *
71+ * Sends a message to the channel the Context was created from.
72+ * This is intended as a lower level function (compared to the other send methods)
73+ * to offer more functionality when needed.
74+ *
75+ * @param message
76+ * The message to send.
77+ */
78+ fun send (message : MessageCreateData ) {
79+ messageChannel.sendMessage(message).submit()
80+ }
81+
6982 /* *
7083 * Sends a message embed to the channel the Context was created from.
7184 *
7285 * @param content
7386 * The content of the message.
7487 *
75- * @return The created message.
88+ * @return The sent message.
7689 */
7790 suspend fun sendAsync (content : String ): Message {
7891 return send0({ setContent(content) }).submit().await()
@@ -84,7 +97,7 @@ class MessageContext(
8497 * @param attachment
8598 * The attachment to send.
8699 *
87- * @return The created message.
100+ * @return The sent message.
88101 */
89102 suspend fun sendAsync (attachment : FileUpload ): Message {
90103 return send0(null , attachment).submit().await()
@@ -96,12 +109,26 @@ class MessageContext(
96109 * @param embed
97110 * Options to apply to the message embed.
98111 *
99- * @return The created message.
112+ * @return The sent message.
100113 */
101114 suspend fun sendAsync (embed : EmbedBuilder .() -> Unit ): Message {
102115 return send0({ setEmbeds(EmbedBuilder ().apply (embed).build()) }).submit().await()
103116 }
104117
118+ /* *
119+ * Sends a message to the channel the Context was created from.
120+ * This is intended as a lower level function (compared to the other send methods)
121+ * to offer more functionality when needed.
122+ *
123+ * @param message
124+ * The message to send.
125+ *
126+ * @return The sent message.
127+ */
128+ suspend fun sendAsync (message : MessageCreateData ): Message {
129+ return messageChannel.sendMessage(message).submit().await()
130+ }
131+
105132 /* *
106133 * Sends the message author a direct message.
107134 *
@@ -110,10 +137,24 @@ class MessageContext(
110137 */
111138 fun sendPrivate (content : String ) {
112139 author.openPrivateChannel().submit()
113- .thenAccept {
114- it.sendMessage(content).submit()
115- .handle { _, _ -> it.delete().submit() }
116- }
140+ .thenCompose { it.sendMessage(content).submit() }
141+ .thenCompose { it.channel.asPrivateChannel().delete().submit() }
142+ }
143+
144+ /* *
145+ * Sends the message author a direct message.
146+ * This is intended as a lower level function (compared to the other send methods)
147+ * to offer more functionality when needed.
148+ *
149+ * @param message
150+ * The message to send.
151+ *
152+ * @return The sent message.
153+ */
154+ fun sendPrivate (message : MessageCreateData ) {
155+ author.openPrivateChannel().submit()
156+ .thenCompose { it.sendMessage(message).submit() }
157+ .thenCompose { it.channel.asPrivateChannel().delete().submit() }
117158 }
118159
119160 private fun send0 (messageOpts : (MessageCreateBuilder .() -> Unit )? = null, vararg files : FileUpload ): RestAction <Message > {
0 commit comments