Sending multiple embeds in one WebhookMesssage
bobooski opened this issue · 2 comments
I'm attempting to get a queue-based system up and running, which will collapse all given embeds into one message to send them speedily, but still comply with Discord's rate limits. Essentially, here is where I am at now:
// called every few seconds
fun run(): () -> Unit = {
if (embeds.isNotEmpty()) {
val toAdd = mutableListOf<WebhookEmbed>()
for (i in 0 until 10) {
val embed = embeds.poll()
if (embed != null) toAdd.add(embed)
}
println("Amount of embeds in toAdd: ${toAdd.size}")
send(WebhookMessage.embeds(toAdd)) // works perfectly as intended
}
}
The amount of embeds that are added is the proper amount, and when I later check directly from the WebhookMessage
object, I get the proper amount. However, in practice, the amount that is sent per message is only one.
I'm not receiving any errors or anything really indicating something not working correctly. I've tried multiple ways of creating the WebhookMessage
object like using the WebhookMessageBuilder
to test if the way they were being created could be the cause, but always got the same result so it must be something about how they're being sent.
I absolutely adore this library... it's been real handy for me and my projects and I hope that this can be fixed soon, or that I could be directed to a possible solution. If you require more information or code snippets, don't hesitate to let me know.
What is the structure of the embeds you are sending? Do they share the same URL and/or titles?
If you send multiple embeds with identical URLs for your EmbedTitle, the discord client will merge them together into a single embed. This is intended behavior, but can be circumvented by augmenting the URL with arbitrary query parameters.
For instance:
client.send(WebhookMessage.embeds(
(1..5).map {
WebhookEmbedBuilder()
.setDescription(it.toString())
.setTitle(EmbedTitle("Title", "https://example.com")
.build()
}
))
Results in:
Whereas the URLs with different query parameters like this
client.send(WebhookMessage.embeds(
(1..5).map {
WebhookEmbedBuilder()
.setDescription(it.toString())
.setTitle(EmbedTitle("Title", "https://example.com?it=$it")
.build()
}
))
Results in:
Ahhhhhh... I wasn't aware of that. Thanks so much!