我尝试向通道发送消息
GatewayDiscordClient gatewayDiscordClient = DiscordClient
.builder("TOKEN")
.build()
.login()
.block();
gatewayDiscordClient.rest().getChannelById(Snowflake.of("ChannelId")).createMessage("p");但是频道不会显示历史记录中的消息。我怎么才能修复它呢?
发布于 2021-10-27 14:38:33
Discord4J利用了“懒惰地执行”的Reactor框架。
您必须在发布者(通常是Mono<T>或Flux<T>)上使用.subscribe()或.block()。
因此,要获得创建消息的代码:gatewayDiscordClient.rest().getChannelById(Snowflake.of("ChannelId")).createMessage("p").subscribe();
但是,我建议您不要使用RestX类,除非您没有使用网关(在您的问题中,网关正在使用)。Rest类通常提供较少的D4J提供的有用抽象,并且旨在由库或not服务器在内部使用,而不是连接到网关的机器人。
要在不使用rest类的情况下发送消息,您的代码将如下所示:
client.getChannelById(channelIdHere)
.ofType(MessageChannel.class)
.flatMap(channel -> channel.createMessage("Your content here"))
.subscribe();https://stackoverflow.com/questions/68130301
复制相似问题