Skip to content

Commit

Permalink
Fix error when using webhook in thread channel (closes #107)
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisD3D committed May 28, 2024
1 parent 8b2d5bd commit 224aef7
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public static Mono<Void> createWebhookMessage(Snowflake channel, String message,
* @return A Mono<Webhook> that completes when the webhook is found or created
*/
public static Mono<Webhook> getMc2DiscordWebhook(Snowflake channel) {
Mono<TopLevelGuildMessageChannel> channelMono = Mc2Discord.INSTANCE.client.getChannelById(channel).ofType(TopLevelGuildMessageChannel.class);
Mono<TopLevelGuildMessageChannel> channelMono = Mc2Discord.INSTANCE.client.getChannelById(channel).ofType(TopLevelGuildMessageChannel.class).switchIfEmpty(Mono.fromRunnable(() -> Mc2Discord.LOGGER.error("Invalid channel type, channel {} must support webhooks (use another channel or another mode)", channel.asString())));
return channelMono.flatMapMany(TopLevelGuildMessageChannel::getWebhooks)
.filter(webhook -> webhook.getName().isPresent() && webhook.getName().get().equals(Mc2Discord.INSTANCE.vars.mc2discord_webhook_name))
.switchIfEmpty(channelMono.flatMap(channel1 -> channel1.createWebhook(Mc2Discord.INSTANCE.vars.mc2discord_webhook_name)))
Expand Down Expand Up @@ -167,6 +167,7 @@ public static Mono<Void> createPlainTextMessage(Snowflake channel, String messag
String finalMessage = message;
return Mc2Discord.INSTANCE.client.getChannelById(channel)
.ofType(MessageChannel.class)
.switchIfEmpty(Mono.fromRunnable(() -> Mc2Discord.LOGGER.error("Invalid channel type, channel {} must support text messages", channel)))
.flatMapMany(messageChannel -> Flux.fromIterable(M2DUtils.breakStringInMessages(finalMessage, 2000, surroundWithCodeBlock))
.flatMap(s -> {
MessageCreateSpec.Builder builder = MessageCreateSpec.builder()
Expand Down Expand Up @@ -208,6 +209,7 @@ public static Mono<Void> createEmbedMessage(Snowflake channel, String message, P
public static Mono<Void> createEmbedMessage(Snowflake channel, String message, Possible<String> username, Possible<String> avatarUrl, List<String> types, Collection<? extends EmbedCreateSpec> embeds, Collection<? extends MessageCreateFields.File> files) {
return Mc2Discord.INSTANCE.client.getChannelById(channel)
.ofType(MessageChannel.class)
.switchIfEmpty(Mono.fromRunnable(() -> Mc2Discord.LOGGER.error("Invalid channel type, channel {} must support text messages", channel)))
.flatMapMany(messageChannel ->
Flux.fromIterable(M2DUtils.breakStringInMessages(message, 4096, false))
.flatMap(s -> {
Expand Down

0 comments on commit 224aef7

Please sign in to comment.