Discord Bot message when user joins voice call

Viewed 326

I've tried to make a bot that sends a message when a user joins a voice call. It doesn't show any error message, but it doesn't work. Here is my code:

package listeners;

import net.dv8tion.jda.api.events.guild.voice.GuildVoiceJoinEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;

public class voiceListener extends ListenerAdapter {
    @Override
    public void onGuildVoiceJoin(GuildVoiceJoinEvent event){
        event.getGuild().getTextChannelById("885172885797343317").sendMessage(event.getVoiceState() + "joined voice channel" + event.getChannelJoined() + ".").queue();
    }
}

The main method is right I guess because another listener works.

1 Answers

I manged to get it working, I have a main startup class for my bot that links all my commands to this one class for easier coding(see below)

public class BotStartup {

public static void main(String[] args) throws LoginException {
        JDABuilder jda = JDABuilder.createDefault("YOUR BOT TOKEN");
        
        jda.setActivity(Activity.playing("STATUS"));
        jda.setStatus(OnlineStatus.ONLINE);
        jda.addEventListeners(new messages());
        jda.addEventListeners(new events());
        jda.addEventListeners(new Clear());
        jda.addEventListeners(new onJoin());
        jda.setChunkingFilter(ChunkingFilter.ALL);
        jda.setMemberCachePolicy(MemberCachePolicy.ALL);
        jda.enableIntents(GatewayIntent.GUILD_MEMBERS);
        jda.build();

onJoin is the class ive named with your code its the same code just a different class name (see below)

public class onJoin extends ListenerAdapter {
@Override
public void onGuildVoiceJoin(GuildVoiceJoinEvent event){
    event.getGuild().getTextChannelById("527272203721637890").sendMessage(event.getVoiceState() + "joined voice channel" + event.getChannelJoined() + ".").queue();
}

}

As you can see in the first image ive used --- jda.addEventListeners(new onJoin());--- This links the command to the start up, id advised doing this aswell as it means for easier coding linking.

This is the outcome VS:DISCORD SERVER:MyDiscordName joined voice channelVC:General Chat - Main(CHAT ID).

Hope This Helped! :)

Related