-
Notifications
You must be signed in to change notification settings - Fork 0
/
youtube-test.js
59 lines (50 loc) · 1.27 KB
/
youtube-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const { Interaction } = require("discord.js");
const { google } = require("googleapis");
const { googleApiKey } = require("./config.json");
const youtube = google.youtube({
version: "v3",
auth: googleApiKey,
});
/**
* Searches and returns an array of DarkDax video links
* @returns array of video links
*/
const search = async () => {
let response = await youtube.search.list({
part: "id,snippet",
q: "DarkDax",
});
var videos = [];
for (const [key, value] of Object.entries(response.data.items)) {
let link = "";
switch (value.id.kind.split("#")[1]) {
case "channel":
link = "https://www.youtube.com/channel/" + value.id.channelId;
break;
case "video":
link = "https://www.youtube.com/watch?v=" + value.id.videoId;
break;
}
videos.push({
title: value.snippet.title,
link: link,
});
}
return videos;
};
/**
* Handles the 'darkdax' slash (/) command
* @param {Interaction} interaction
*/
const handleDarkDax = async (interaction) => {
let links = await search();
let reply = "";
links.forEach(element => {
reply = reply + element.link + "\n";
});
interaction.reply({
content: reply,
ephemeral: true
});
};
module.exports.handleDarkDax = handleDarkDax;