1

我有以下错误no instance(s) of type variable(s) R exist so that void conforms to Mono<? extends R>。我将如何解决这个问题?我用 Discord4J 在 Java 中编写了一个不和谐的机器人。当用户对相应性别 ID 的机器人表情符号做出反应时,喜欢写入数据库(或在此示例中简单地打印)用户及其性别。

我有一个数据库方法:

    public static void setUserGender(String u, ReactionEmoji e){
        String gender = (e.equals(EmojiUtils.EMOJI_MALE)) ? "male" : "female";
        Database.write(u, gender); // implementation prints the result for now
    }

反应命令是这样的:

    public Mono<Void> issueCommand(final String[] args, final MessageCreateEvent event, final GuildSettings settings) {
        Message msg =  MessageUtils.sendMessage(event, "Welcome " + event.getMember().get().getNicknameMention()
                + "! It looks like you're new around here.\n No worries! "
                + "Lets get you started. What do you identify as?");
        Mono<Void> maleReaction = msg.addReaction(EmojiUtils.EMOJI_MALE);
        Mono<Void> femaleReaction = msg.addReaction(EmojiUtils.EMOJI_FEMALE);
        Mono<Void> reactorEvent = event.getClient().on(ReactionAddEvent.class)
                .filter(e -> e.getMessageId().equals(event.getMessage().getId())) // on same message
                .filter(e -> e.getUserId().equals(event.getMember().get().getId())) // by same person
                .next()
                .flatMap(e -> Database.setUserGender(e.getUser().toString(), e.getEmoji()))
                .then();

        return Mono.when(reactorEvent, maleReaction, femaleReaction);
    }

编辑:错误发生在这一行.flatMap(e -> Database.setUserGender(e.getUser().toString(), e.getEmoji()))

Edit2:我尝试了第一个使用 .flatMapMany() 的建议。我收到同样的错误:

StartCommand.java:58: error: incompatible types: cannot infer type-variable(s) R
                .flatMapMany(e -> Database.setUserGender(e.getUser().toString(), e.getEmoji()))
                            ^
    (argument mismatch; bad return type in lambda expression
      void cannot be converted to Publisher<? extends R>)
  where R,T are type-variables:
    R extends Object declared in method <R>flatMapMany(Function<? super T,? extends Publisher<? extends R>>)
    T extends Object declared in class Mono
4

0 回答 0