JDA 将 DM 发送到 ping 角色

时间:2021-07-25 06:42:17

标签: java discord discord-jda

package com.commands;

import com.company.Main;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Role;
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import org.jetbrains.annotations.NotNull;

public class MassDM extends ListenerAdapter {
    @Override
    public void onGuildMessageReceived(@NotNull GuildMessageReceivedEvent event) {
        super.onGuildMessageReceived(event);
        String[] args = event.getMessage().getContentRaw().split(" ");
        if(args[0].equalsIgnoreCase(Main.BOT_PREFIX+"massdm")){
            Role role = event.getMessage().getMentionedRoles().get(0);
            for(Member member: event.getGuild().getMembersWithRoles(role)){
                System.out.println(member);
                    try{
                        System.out.println(member.toString());
                        member.getUser().openPrivateChannel()
                                .flatMap(channel -> channel.sendMessage("Hello sir"))
                                .queue();
                    }catch (Exception e){
                    }



            }
        }


    }
}

你好,所以我正在写一个不和谐的机器人给具有特定角色的人。但是,在我的代码中不起作用,我错过了什么?我正在使用 JDA 4.3

0 个答案:

没有答案