[英]Discord Bot message when user joins voice call
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.我猜 main 方法是正确的,因为另一个监听器起作用了。
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)我设法让它工作,我有一个主启动 class 用于我的机器人,它将我所有的命令链接到这个 class 以便更容易编码(见下文)
public class BotStartup {公共 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) onJoin 是我用您的代码命名的 class 其相同的代码只是不同的 class 名称(见下文)
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.正如您在我使用的第一张图片中看到的 --- jda.addEventListeners(new onJoin());--- 这将命令链接到启动,id 建议这样做,因为这意味着更容易编码链接。
This is the outcome VS: DISCORD SERVER : MyDiscordName joined voice channelVC:General Chat - Main( CHAT ID ).这是结果 VS: DISCORD 服务器: MyDiscordName加入了语音频道 VC:General Chat - Main( CHAT ID )。
Hope This Helped: :)希望这有帮助::)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.