0
votes

I'm having a problem with discord-player. When I execute !play URL, it joins my channel, it plays the song and it's perfectly fine, but when instead of passing a link I pass a search query ex. !play Despacito, it gets frozen and then cancels the play event. What is going on? On the video I have a program called NetLimiter4 that is monitoring how much bandwidth is used by any app. You can see that when I type in despacito it tries to search it and then gives up, but when I provide a link, it starts to play it. I checked everything, I even tried to put breakpoints in the Player class. From my observations, it tries to search the query, and it's successful but for some reason, it fails. No stack trace, no nothing

import * as Discord from "discord.js";
import {Player} from "discord-player";
const client = new Discord.Client();
const player = new Player(client);



client.on("ready", ()=>{
  console.log("ready");
  
})

client.on("message", async (message)=>{
  let args = message.content.split(" ");
  if(args[0] == "!play" && args[1]){
    console.log("playin0");

    
    await player.play(message, args[1]);

    console.log("playing");
    
  }else if(args[0] == "!stop"){
    if(!player.isPlaying(message)) return message.channel.send("Can't stop playing nothing");

    player.stop(message);
    
  }
})

player.on("trackStart", (message, track) =>{
  message.channel.send(`Started playing ${track.title}!`);
})



client.login("token");
1

1 Answers

1
votes

You might be using discord-player above v2 , and yeah discord-player has built in search feature so you need to add this code -

player.on('searchResults', (message, query, tracks) => {
const embed = new Discord.MessageEmbed()
    .setAuthor(`Search Reults`)
    .setDescription(tracks.map((k, x) => `${x}. ${k.title}`))
    .setFooter('Send the number of the song you want to play!')
    message.channel.send(embed);
})

where x is the number and k belongs to Track class, Now once the user enters a number like 1 it starts playing the song!