英文:
Why is search not working with "ytsearch:" in lavaplayer, JDA
问题
我正在使用Java和Lavaplayer为Discord创建一个音乐机器人。我尝试使用"ytsearch:"来根据标题查找音轨。在/play中的任何输入都会返回noMatches。与此同时,从链接下载音乐正常工作。我正在使用最新的JDA(5.0.0-beta.9)和Lavaplayer(1.3.77)。
我的代码如下:
public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent event) {
if (event.getName().equals("play")) {
event.getGuild().getAudioManager().openAudioConnection(event.getMember().getVoiceState().getChannel());
String name = event.getOption("name").getAsString();
try {
new URI(name);
} catch (URISyntaxException e) {
name = "ytsearch:" + name;
}
PlayerManager playerManager = PlayerManager.get();
event.reply("Playing").setEphemeral(true).submit();
playerManager.play(event.getGuild(), name);
}
}
请注意,这只是代码的一部分,它用于处理/play命令。如果您需要更多帮助,请提供更多上下文或问题的详细信息。
英文:
I am creating a music bot for discord in Java, lavaplayer. I'm trying to find a track by title using "ytsearch:" Any input in /play will return noMatches. At the same time, downloading music from the link works fine. I am using the latest JDA (5.0.0-beta.9) and lavaplayer (1.3.77).
I tried to copy the code from the manuals, but what works for the authors with a similar version does not work for me.
My code:
- /play
public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent event) {
if (event.getName().equals("play")) {
event.getGuild().getAudioManager().openAudioConnection(event.getMember().getVoiceState().getChannel());
String name = event.getOption("name").getAsString();
try {
new URI(name);
} catch (URISyntaxException e) {
name = "ytsearch:" + name;
}
PlayerManager playerManager = PlayerManager.get();
event.reply("Playing").setEphemeral(true).submit();
playerManager.play(event.getGuild(), name);
}
}
答案1
得分: 0
抱歉,你提供的代码部分已经是英文,无需翻译。如果你有其他需要翻译的文本,请随时提供。
英文:
The problem is that the try block never threw the expected error. Working code:
public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent event) {
if (event.getName().equals("play")) {
event.getGuild().getAudioManager().openAudioConnection(event.getMember().getVoiceState().getChannel());
String name = event.getOption("name").getAsString();
try {
new URL(name);
} catch (MalformedURLException e) {
name = "ytsearch:" + name;
}
PlayerManager playerManager = PlayerManager.get();
playerManager.play(event.getGuild(), name);
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论