-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyt_search.js
102 lines (93 loc) · 2.74 KB
/
yt_search.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
const http = require("http");
http
.createServer(function (req, res) {
res.write("yt_search.js is active.\nPlease check it.");
res.end();
})
.listen(8080);
// Discord bot implements
const { YouTubePlugin } = require("@distube/youtube");
const youTubePlugin = new YouTubePlugin();
const { Client, GatewayIntentBits } = require("discord.js");
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildVoiceStates,
],
});
require("dotenv").config();
const prefix = "pj!";
const token = process.env.token;
// botが準備できれば発動され、 上から順に処理される。
client.on("ready", () => {
// コンソールにReady!!と表示
console.log("Ready!!");
// ステータスを設定する
setInterval(() => {
client.user.setActivity({
name: `所属サーバー数は、${client.guilds.cache.size}サーバー| Ping値は、${client.ws.ping}msです`,
});
}, 10000);
client.channels.cache.get("889486664760721418").send("起動しました!");
// readyイベントここまで
});
// botがメッセージを受信すると発動され、 上から順に処理される。
client.on("messageCreate", async (message) => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).trim().split(" ");
const command = args.shift().toLowerCase();
if (command === "help") {
message.channel.send({
embeds: [
{
title: "HELP",
description: "ないよう",
color: 0x227fff,
timestamp: new Date(),
thumbnail: {
url: "attachment://logo.png",
},
footer: {
text: "This bot is made by Hoshimikan6490",
icon_url: "attachment://me.png",
},
},
],
files: [
{
attachment: "images/logo.png",
name: "logo.png",
},
{
attachment: "images/me.png",
name: "me.png",
},
],
});
} else if (command === "yt_search") {
const AKB = message.content.split(" ").slice(1).join(" ");
if (!AKB)
return message.channel.send(
"エラー:空白がないまたは検索内容を書いていません"
);
const results = await youTubePlugin.search(AKB, {
type: "video",
limit: 5,
});
const maxTracks = results.slice(0, 10);
message.channel.send(
`${maxTracks
.map(
(song, i) =>
`**${i + 1}**. [${song.name}](${song.url}) | \`${
song.uploader.name
}\``
)
.join("\n")}`
);
}
});
// botログイン
client.login(token);