Home > other >  Crosspost Discord Message using Discord4j
Crosspost Discord Message using Discord4j

Time:06-12

I have a DiscordBot which was written with Discord4j using Kotlin. I send EmbedMessages with it and I want to publish these messages automatically. Does anyone have a clue how to do this? I have an embedbuilder and send the message with the following function.

fun sendEmbedMessage(gateway: GatewayDiscordClient, embed: EmbedCreateSpec, channelId: String) {
    gateway.getChannelById(Snowflake.of(channelId))
        .ofType(GuildMessageChannel::class.java)
        .flatMap { channel -> channel.createMessage(embed) }
        .subscribe()
}

Thanks in advance!

CodePudding user response:

You can use publish:

fun sendEmbedMessage(gateway: GatewayDiscordClient, embed: EmbedCreateSpec, channelId: String) {
    gateway.getChannelById(Snowflake.of(channelId))
        .ofType(GuildMessageChannel::class.java)
        .flatMap { channel -> channel.createMessage(embed) }
        .flatMap { message -> message.publish() }
        .subscribe()
}
  • Related