为什么 onGuildMemberLeave 事件不起作用(Discord Java JDA)

huangapple go评论90阅读模式
英文:

Why onGuildMemberLeave event not working (Discord Java JDA)

问题

The onGuildMemberLeave event doesn't work and I don't know why. I tried to use intents, activate intent authorizations on discord.com, but still not fixed.

The JDABuilder method:

public static void buildJDA(){
    try {
        jdaBuilder.createDefault(Configuration.getToken())
                .enableIntents(GatewayIntent.GUILD_PRESENCES,
                        GatewayIntent.GUILD_BANS,
                        GatewayIntent.DIRECT_MESSAGES,
                        GatewayIntent.DIRECT_MESSAGE_REACTIONS,
                        GatewayIntent.GUILD_MEMBERS,
                        GatewayIntent.GUILD_INVITES)
                .enableCache(CacheFlag.ACTIVITY,
                        CacheFlag.CLIENT_STATUS,
                        CacheFlag.EMOTE,
                        CacheFlag.MEMBER_OVERRIDES)
                .addEventListeners(new JdaManager())
                .addEventListeners(new EngineListeners())
                .addEventListeners(new ElkirListeners())
                .build();
    } catch (LoginException e) {
        e.printStackTrace();
    }
}

The onGuildMemberLeave event (ElkirListener):

@Override
public void onGuildMemberLeave(@Nonnull GuildMemberLeaveEvent event) {

    if(!Configuration.isSnapshotEnabled()){

        if(event.getGuild().getId().equalsIgnoreCase("701834905021186090")){
            EmbedBuilder builder = new EmbedBuilder()
                    .setAuthor(event.getUser().getAsTag(), null, event.getUser().getAvatarUrl())
                    .setColor(Color.red)
                    .setDescription("Tu nous à quittés, bonne continuation mon ami.");

            event.getGuild().getTextChannelById("701898572534382592").sendMessage(builder.build()).queue();
        }

        if(event.getGuild().getId().equalsIgnoreCase("465583093357477896")){
            EmbedBuilder builder = new EmbedBuilder()
                    .setAuthor(event.getUser().getAsTag(), null, event.getUser().getAvatarUrl())
                    .setColor(Color.red)
                    .setDescription("Tu nous à quitté, bonne continuation mon ami.");

            event.getGuild().getTextChannelById("568803340541231125").sendMessage(builder.build()).queue();
        }
    }
}

What am I missing?

英文:

The onGuildMemberLeave event doesn't work and I don't know why. I tried to use intents, activate intent authorizations on discord.com, but still not fixed.

The JDABuilder method:

public static void buildJDA(){
    try {
        jdaBuilder.createDefault(Configuration.getToken())
                .enableIntents(GatewayIntent.GUILD_PRESENCES,
                        GatewayIntent.GUILD_BANS,
                        GatewayIntent.DIRECT_MESSAGES,
                        GatewayIntent.DIRECT_MESSAGE_REACTIONS,
                        GatewayIntent.GUILD_MEMBERS,
                        GatewayIntent.GUILD_INVITES)
                .enableCache(CacheFlag.ACTIVITY,
                        CacheFlag.CLIENT_STATUS,
                        CacheFlag.EMOTE,
                        CacheFlag.MEMBER_OVERRIDES)
                .addEventListeners(new JdaManager())
                .addEventListeners(new EngineListeners())
                .addEventListeners(new ElkirListeners())
                .build();
    } catch (LoginException e) {
        e.printStackTrace();
    }
}

The onGuildMemberLeave event (ElkirListener):

@Override
public void onGuildMemberLeave(@Nonnull GuildMemberLeaveEvent event) {

    if(!Configuration.isSnapshotEnabled()){

        if(event.getGuild().getId().equalsIgnoreCase("701834905021186090")){
            EmbedBuilder builder = new EmbedBuilder()
                    .setAuthor(event.getUser().getAsTag(), null, event.getUser().getAvatarUrl())
                    .setColor(Color.red)
                    .setDescription("Tu nous à quittés, bonne continuation mon ami.");

            event.getGuild().getTextChannelById("701898572534382592").sendMessage(builder.build()).queue();
        }

        if(event.getGuild().getId().equalsIgnoreCase("465583093357477896")){
            EmbedBuilder builder = new EmbedBuilder()
                    .setAuthor(event.getUser().getAsTag(), null, event.getUser().getAvatarUrl())
                    .setColor(Color.red)
                    .setDescription("Tu nous à quitté, bonne continuation mon ami.");

            event.getGuild().getTextChannelById("568803340541231125").sendMessage(builder.build()).queue();
        }
    }
}

What am I missing?

答案1

得分: 0

你不应该使用已弃用的功能,比如 GuildMemberLeaveEvent

文档建议你使用代替的 GuildMemberRemoveEvent

英文:

You shouldn't be using deprecated features like the GuildMemberLeaveEvent.

The documentation tells you to use GuildMemberRemoveEvent instead.

huangapple
  • 本文由 发表于 2020年7月23日 22:57:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/63057201.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定