0

I am making a Discord bot which when you run a command by typing **-yt ** then the channel name after, I want it to show info about that channel using Javascript. Here is my code so far of which I want it to show info about a channel with the name of whatever they input after typing **-yt **

Here is my code so far and I changed areas to show where the channel id should come from the input:

    if(command === "-yt") {
    var request = require('request');
const input = args.join(" ");
const config = require("config.json");

var id = `${input}`;
var key = `${config.key}`;

var url = "https://www.googleapis.com/youtube/v3/channels?part=statistics&id=" + id + "&key=" + key;

request({
    method: 'GET',
    url: url
}, function (err, response, text) {
    if (err) {

        return;
    }

    var json = JSON.parse(text);
  message.channel.send({embed: {
  color: 3092790,
  description: "```"+ `Name: ${input}`+ "```"+ "```"+ `Subscribers: ${json.items[0].statistics.subscriberCount}`+ "```"+ "```"+ `\nViews: ${json.items[0].statistics.viewCount}`+ "```"+ "```"+ `Other: Coming Soon`+ "```"
  }})})}})
moie
  • 66
  • 6
  • Are you accessing the properties in the right way? Could you maybe show us some example JSON you get from the API because we can't make a request without a valid key. – axtck Nov 13 '20 at 17:56
  • @B4ndy: you could very much use your own key; if you don't have one, Google developers console will provide one immediately for free once asking it. – stvar Nov 13 '20 at 18:01
  • 1
    Please take into account that *channel name* and *channel ID* are two different concepts with respect to YouTube Data API. If you read the [answer I provided recently to a similar question](https://stackoverflow.com/a/64302234/8327971), you'll see that, for example, the channel identified by the ID `UCvewcgPDiYrVNiyh8kpOnFQ` has the name `leagueoflegends`. I recommend to update your post above, such that to distinguish between the two concepts: does your input need to be a channel ID or a channel name? Then I'll probably be able to help you further. – stvar Nov 13 '20 at 18:02
  • @stvar Input needs to be a channel name so like: Pewdiepie then it'd convert that to a channel ID so that it can get the sub count of that channel and set that as a variable to use in other parts of the code – moie Nov 16 '20 at 17:06
  • OK. I see. But please also acknowledge that [the exact number of subscribers](https://stackoverflow.com/a/63537230/8327971) of a given channel is a private info of that channel. – stvar Nov 16 '20 at 18:02
  • @stvar if someone on Youtube searches for your channel and they can see the subscriber count that's not private info – moie Nov 18 '20 at 14:45
  • @moies: please read carefully what I have stated: ***the exact number of subscribers** of a given channel is a private info of that channel.* The numbers seen on YouTube's site and those provided by the YouTube Data API are *numbers rounded down to three significant figures.* The exact numbers are (am stating this again!, [quoting myself](https://stackoverflow.com/a/63537230/8327971)!) available only to owners of the respective channels in YouTube Studio and YouTube Analytics. – stvar Nov 18 '20 at 15:04

0 Answers0