-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
160 lines (138 loc) · 4.23 KB
/
index.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// v11 and v12 and v13 :3
/*
//////// [1] ////////
// Discord.js v11.6.4
> npms: {
Discord.js: ^11.6.4
}
const { Client, RichEmbed } = require("discord.js");
const client = new Client();
client.login("YOU BOT TOKEN");
client.on("message", message => {
const file = message.attachments.first();
if (message.content.startsWith("djs!play")) {
try {
const channel = message.member.voiceChannel;
const Embed = new Discord.RichEmbed()
.setAuthor("Command: play")
.setFields: (
{
name: "Usege",
value: `djs!play (file)`,
inline: true
},
{
name: "Examples",
value: `djs!play ...`,
inline: true
})
.setDescription("music command: play songs")
if (!channel || !file) return message.channel.send(Embed);
channel.join().then(connection => {
const dispatcher = connection.playFile(file.url);
message.channel.send("> playing: `" + file.name + "`, size: `" + file.size + "B`);
});
} catch (error) {
message.channel.send(error.message || "Error");
}
}
});
*/
/*
//////// [2] ////////
// Discord.js v12.5.3
> npms: {
Discord.js: ^12.5.3,
node-opus: ^0.3.3
ffmpeg: ^0.0.3
}
// FFmpeg
const ffmpeg = require("ffmpeg");
const { Client, MessageEmbed } = require("discord.js");
const client = new Client();
client.on("message", async message => {
const file = message.attachments.first();
if (message.content.startsWith("djs!play")) {
try {
const channel = message.member.voice.channel;
const Embed = new MessageEmbed()
.setAuthor("Command: play")
.setFields: (
{
name: "Usege",
value: `djs!play (file)`,
inline: true
},
{
name: "Examples",
value: `djs!play ...`,
inline: true
})
.setDescription("music command: play songs")
if (!channel || !file) return message.channel.send({ embed: Embed });
channel.join().then(connection => {
const dispatcher = connection.play(file.url);
message.channel.send("> playing: `" + file.name + "`, size: `" + file.size + "B`);
});
} catch (error) {
message.channel.send(error.message || "Error");
}
}
});
*/
/*
//////// [3] ////////
// Discord.js v13.1.0
> npms: {
Discord.js: ^13.1.0,
ffmpeg: ^0.0.4,
node-opus: ^0.3.3
@discordjs/voice: ^0.6.0
}
*/
//FFmpeg
const ffmpeg = require("ffmpeg");
const { Client, Intents, VoiceChannel, Discord, MessageEmbed } = require("discord.js");
const client = new Client({ intents: [ Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_VOICE_STATES ]});
const { joinVoiceChannel, createAudioPlayer, createAudioResource, entersState, StreamType, AudioPlayerStatus, VoiceConnectionStatus } = require("@discordjs/voice");
const Player = createAudioPlayer();
client.login("YOU BOT TOKEN");
client.on("messageCreate", async message => {
if (message.content.startsWith("djs!play")) {
const file = message.attachments.first();
const channel = message.member.voice.channel;
const Embed = new MessageEmbed()
.setAuthor("Command: play")
.addFields(
{
name: "Usege",
value: `djs!play (file)`,
inline: true
},
{
name: "Examples",
value: `djs!play ...`,
inline: true
})
.setDescription("music command: play songs");
if (!channel || !file) return message.channel.send({ embeds: [Embed] });
const connection = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator
});
try {
connection;
connection.subscribe(Player);
const resource = createAudioResource(file.url, {
inputType: StreamType.Arbitrary
});
Player.play(resource);
message.channel.send({
content: "> playing: `" + file.name + "`, size: `" + file.size + "B`"
});
} catch (error) {
message.channel.send({ content: error.message || "Error" });
}
}
});