@@ -14,6 +14,7 @@ import net.dv8tion.jda.api.events.message.MessageReceivedEvent
14
14
import net.dv8tion.jda.api.requests.RestAction
15
15
import net.dv8tion.jda.api.utils.FileUpload
16
16
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder
17
+ import net.dv8tion.jda.api.utils.messages.MessageCreateData
17
18
import java.util.regex.Pattern
18
19
19
20
class MessageContext (
@@ -66,13 +67,25 @@ class MessageContext(
66
67
send0({ setEmbeds(EmbedBuilder ().apply (embed).build()) }).submit()
67
68
}
68
69
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
+
69
82
/* *
70
83
* Sends a message embed to the channel the Context was created from.
71
84
*
72
85
* @param content
73
86
* The content of the message.
74
87
*
75
- * @return The created message.
88
+ * @return The sent message.
76
89
*/
77
90
suspend fun sendAsync (content : String ): Message {
78
91
return send0({ setContent(content) }).submit().await()
@@ -84,7 +97,7 @@ class MessageContext(
84
97
* @param attachment
85
98
* The attachment to send.
86
99
*
87
- * @return The created message.
100
+ * @return The sent message.
88
101
*/
89
102
suspend fun sendAsync (attachment : FileUpload ): Message {
90
103
return send0(null , attachment).submit().await()
@@ -96,12 +109,26 @@ class MessageContext(
96
109
* @param embed
97
110
* Options to apply to the message embed.
98
111
*
99
- * @return The created message.
112
+ * @return The sent message.
100
113
*/
101
114
suspend fun sendAsync (embed : EmbedBuilder .() -> Unit ): Message {
102
115
return send0({ setEmbeds(EmbedBuilder ().apply (embed).build()) }).submit().await()
103
116
}
104
117
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
+
105
132
/* *
106
133
* Sends the message author a direct message.
107
134
*
@@ -110,10 +137,24 @@ class MessageContext(
110
137
*/
111
138
fun sendPrivate (content : String ) {
112
139
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() }
117
158
}
118
159
119
160
private fun send0 (messageOpts : (MessageCreateBuilder .() -> Unit )? = null, vararg files : FileUpload ): RestAction <Message > {
0 commit comments