简体   繁体   中英

GuildMemberJoin PN Message

Hey I want to send a welcome message to new people. This is my Code. Im very new at Java please help me to get this feature working:

package de.backxtar.listener;

import java.time.OffsetDateTime;

import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;

public class JoinListener extends ListenerAdapter {

    @Override
    public void onGuildMemberJoin(GuildMemberJoinEvent event) {
        Member member = event.getMember();

        if((event.getGuild().getDefaultChannel()) != null) {

            EmbedBuilder builder = new EmbedBuilder();

            builder.setColor(0xf22613);
            builder.setThumbnail("http://image.png");
            builder.setTitle("Willkommen auf Da Hood!");
            builder.setFooter("Powered by Backxtar.");
            builder.setTimestamp(OffsetDateTime.now());
            builder.setDescription("Herzlich willkommen" + member.getAsMention() + "auf **Da Hood**!\n"
                    + "[**Da Hood - The Best Gaming-Discord!**](https://xyz.gg)");

            member.getUser().openPrivateChannel().queue((ch) -> {
                ch.sendMessage(builder.build()).queue();
            });
        }
    }
}

How does this funktion to be? if((event.getGuild().getDefaultChannel()) != null) {

Thanks!!

first of all, event.getGuild().getDefaultChannel() returns you the channel set for " System Messages Channel " in the server settings, or if none is set there, the first text channel on the Discord Server.

Secondly, unfortunately I cannot tell you why your code does not work because it works perfectly for me, maybe it could be because your Discord server does not have TextChannel if that is the case try if your code works when you create a TextChannel on your Discord server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM