question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Says 'Please provide a link" after i put a link in?

See original GitHub issue

const Discord = require(‘discord.js’); const YTDL = require(‘ytdl-core’);

const TOKEN = “NDA5OTc4Mjg2NjkzNjc5MTA0.DVmdow.yI4l0Z2UtZ2RgSBJqeWjkUtg7I0”; const PREFIX = “dm.”;

function play(connection, message) { var server = servers[message.guild.id]

server.dispatcher = connection.playStream(YTDL(server.queue[0], {filter: "audioonly"}));

server.queue.shift()

server.dispatcher.on("end", function() {
    if (!server.queue[0]) play(connection, message);
    else connection.disconnect();
});

}

const bot = new Discord.Client()

const servers = {};

bot.on(“ready”, function() { console.log(“I’m ready to play music !”)

bot.user.setPresence({game: {name: Bot In Development | Users: ${bot.users.size},type: 0}});

bot.on(‘message’, function(message) { if (message.author.equals(bot.user)) return;

if (!message.content.startsWith(PREFIX)) return;

var args = message.content.substring(PREFIX.length).split(" ");

switch (args[0].toLowerCase()) {
    case "play":
        if (args[1]) {
            message.channel.send('Please provide a link!');
            return;
        }

        if (!message.member.voiceChannel) {
            message.channel.send('You must be in a voice channel!');
            return;
        }

        if(servers[message.guild.id]) servers[message.guild.id] = {
            queue: []
        };

        var server = servers[message.guild.id]

        if (!message.guild.voiceConnection) message.member.voiceChannel.join().then(function(connection) {
            play(connection, message);
        });
        break;
    case "skip":
        var server = servers[message.guild.id];

        if (server.dispatcher) server.dispatcher.end();
        break;
    case "stop":
        var server = servers[message.guild.id];

        if(!message.guild.voiceConnection) message.guild.voiceConnection.disconnect();
        break;
}

})})

bot.login(TOKEN);

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
FireController1847commented, Feb 5, 2018

@GamerXD4 I would reset your token IMMIDEATLY as you’ve just given it away on a public platform, and users will abuse it by destroying anything the bot is connected on.

With that out of the way, make sure “server.queue[0]” is returning a valid YouTube URL. Try using console.log(server.queue[0]); before running it and send the results here.

Here’s his code cleaned up and put into one code block:

const Discord = require('discord.js');
const YTDL = require('ytdl-core');
const TOKEN = "x";
const PREFIX = "dm.";

function play(connection, message) {
  var server = servers[message.guild.id];
  server.dispatcher = connection.playStream(YTDL(server.queue[0], {
    filter: "audioonly"
  }));
  server.queue.shift()
  server.dispatcher.on("end", function() {
    if (!server.queue[0]) play(connection, message);
    else connection.disconnect();
  });
}
const bot = new Discord.Client()
const servers = {};
bot.on("ready", function() {
  console.log("I'm ready to play music !")
  bot.user.setPresence({
    game: {
      name: Bot In Development | Users: $ {
        bot.users.size
      },
      type: 0
    }
  });
  bot.on('message', function(message) {
    if (message.author.equals(bot.user)) return;
    if (!message.content.startsWith(PREFIX)) return;
    var args = message.content.substring(PREFIX.length).split(" ");
    switch (args[0].toLowerCase()) {
      case "play":
        if (args[1]) {
          message.channel.send('Please provide a link!');
          return;
        }
        if (!message.member.voiceChannel) {
          message.channel.send('You must be in a voice channel!');
          return;
        }
        if (servers[message.guild.id]) servers[message.guild.id] = {
          queue: []
        };
        var server = servers[message.guild.id]
        if (!message.guild.voiceConnection) message.member.voiceChannel.join().then(function(connection) {
          play(connection, message);
        });
        break;
      case "skip":
        var server = servers[message.guild.id];
        if (server.dispatcher) server.dispatcher.end();
        break;
      case "stop":
        var server = servers[message.guild.id];
        if (!message.guild.voiceConnection) message.guild.voiceConnection.disconnect();
        break;
    }
  })
})
bot.login(TOKEN);
1reaction
TimeForANinjacommented, Feb 5, 2018

None of this is related to ytdl-core but whatever

A few of your problems

if (args[1]) {
          message.channel.send ('Please  provide a link!');
         return;
        }

=> if a link is provided, respond there is no link

if (server.dispatcher)

=> server can be undefined when skipping

if (servers[message.guild.id]) servers[message.guild.id] = {
          queue: []
        };

=> better add it when it’s not in there

const servers = {};

=> better use a Map for this

UR never pushing items to ur music q nether validating/handling ytdl’s video not found errors

server.dispatcher.on("end", function() {
    if (!server.queue[0]) play(connection, message);
    else connection.disconnect();
  });

=> when we have nothing in the q play it?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Create or edit a hyperlink - Microsoft Support
The fastest way to create a basic hyperlink in a Microsoft 365 document is to press ENTER or the SPACEBAR after you type...
Read more >
HTML Link – How to Insert a Link to a Website with HREF Code
We'll learn how to create a hyperlink for this use case when we learn about the href attribute. 2. When you want to...
Read more >
Fix a Broken Link in Your Email (After You've Hit Send)
Did you send a marketing email with a bad or broken link? Here are three ways you can fix it after you've already...
Read more >
How to Add a Hyperlink to an Email - GroupMail
When a recipient of your email clicks on Click Here, it will take them to the website that you entered as the hyperlink....
Read more >
Beginner's Guide on How to Add a Link in WordPress
Once you create a new post or edit an existing one, you should click the (+) icon to create a new block. After...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found