Discord4J: No instance(s) of type variable(s) R exist so that void conforms to Mono<? extends R>

℡╲_俬逩灬. 提交于 2021-01-28 11:30:06

问题


I have the following error no instance(s) of type variable(s) R exist so that void conforms to Mono<? extends R>. How would I resolve this? Im writing a discord bot in java with Discord4J. When a user reacts to the bot emoji for the corresponding gender id like to write to the database (or in this example simply print) the user and their gender.

I have a database method:

    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
    }

and the reactive command is this:

    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);
    }

Edit: The error occurs on this line .flatMap(e -> Database.setUserGender(e.getUser().toString(), e.getEmoji()))

Edit2: I tried the first suggestion to use .flatMapMany(). I recieve the same error:

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

来源:https://stackoverflow.com/questions/65767618/discord4j-no-instances-of-type-variables-r-exist-so-that-void-conforms-to-m

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!