-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
239 lines (211 loc) · 6.62 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
require('dotenv').config();
const { MessageEmbed, Client, Collection } = require('discord.js');
const DisTube = require('distube');
const { SpotifyPlugin } = require('@distube/spotify');
const PREFIX = '!!';
const client = new Client({
intents: ['GUILDS', 'GUILD_VOICE_STATES', 'GUILD_MESSAGES'],
});
client.options.http.api = 'https://discord.com/api';
const distube = new DisTube.default(client, {
leaveOnStop: false,
plugins: [new SpotifyPlugin()],
});
client.commands = new Collection();
client.once('ready', () => {
console.log(`${client.user.username} Logged in!`);
presence();
distube.on('error', (channel, error) => {
channel.send(`An error encoutered: ${error.message}`);
});
});
const embedBoilerplate = ({ title, description, color, footer }) => {
const messageEmbed = new MessageEmbed()
.setTitle(title)
.setDescription(description)
.setColor(color)
.setFooter(footer);
return { embeds: [messageEmbed] };
};
const presence = (songName) => {
songName
? client.user.setPresence({
activities: [{ name: `${songName}` }],
status: 'dnd',
})
: client.user.setPresence({
activities: [{ name: `${PREFIX}help` }],
status: 'online',
});
};
let channelAuth = {
id: '',
auth: false,
};
client.on('messageCreate', async (message) => {
if (!message.content.startsWith(PREFIX) || message.author.bot) return;
const args = message.content.slice(PREFIX.length).trim().split(/ +/g);
const command = args.shift().toLowerCase();
if (command === 'auth' || command === 'a') {
channelAuth = {
id: message.channelId,
auth: true,
};
await message.channel.send(
embedBoilerplate({
title: `:white_check_mark: Comand: Auth!`,
description: ` You autorized ${client.user.username}`,
color: 'BLACK',
footer: `~${command}~`,
})
);
}
if (message.channelId != channelAuth.id) {
message.channel.send(
`:x: **The ${client.user.username} cannot be used here**`
);
return;
}
if (command === 'help' || command === 'h') {
await message.channel.send(
embedBoilerplate({
title: `**Hi! I'm ${client.user.username} this are the commands: ** :face_with_monocle: `,
description: `:arrow_forward: **${PREFIX}play** or **${PREFIX}p** : to play music by url or searching it\n
:stop_button: **${PREFIX}stop** or **${PREFIX}s** : to stop music and disconect bot\n
:pause_button: **${PREFIX}paus**e or **${PREFIX}pp** : to pause song\n
:arrow_forward: **${PREFIX}resume** or **${PREFIX}r** : to resume song\n
:track_next: **${PREFIX}skip** or **${PREFIX}ss** : to skip song\n
:asterisk: **${PREFIX}queue** or **${PREFIX}q** : to see the queue\n
:musical_note: **${PREFIX}playing** or **${PREFIX}pl** : to watch the playback\n
:green_circle: ** Spotify and ** :red_circle: **Youtube support!** `,
color: 'BLUE',
footer: `~${command}~`,
})
);
}
if (command === 'play' || command === 'p') {
try {
args.length
? await distube.play(message, args.join(' '))
: message.channel.send('Enter a url or search pls!');
} catch (error) {
message.channel.send(`:x: **${error.message}**`);
}
}
if (command === 'stop' || command === 's') {
try {
await distube.stop(message);
await message.channel.send(
embedBoilerplate({
title: `:stop_button: Comand: Stop!`,
description: 'Music stopped',
color: 'RED',
footer: `~${command}~`,
})
);
presence();
} catch (error) {
message.channel.send(`:x: **${error.message}**`);
}
}
if (command === 'pause' || command === 'pp') {
try {
distube.pause(message);
await message.channel.send(
embedBoilerplate({
title: `:pause_button: Comand: Pause!`,
description: 'Music paused',
color: 'YELLOW',
footer: `~${command}~`,
})
);
} catch (error) {
message.channel.send(`:x: **${error.message}**`);
}
}
if (command === 'resume' || command === 'r') {
try {
distube.resume(message);
await message.channel.send(
embedBoilerplate({
title: `:arrow_forward: Comand: Resume!`,
description: 'Music resumed',
color: 'GREEN',
footer: `~${command}~`,
})
);
} catch (error) {
message.channel.send(`:x: **${error.message}**`);
}
}
if (command == 'skip' || command === 'ss') {
try {
await distube.skip(message);
message.channel.send(
embedBoilerplate({
title: `:track_next: Comand: Skip!`,
description: 'Music Skipped',
color: 'ORANGE',
footer: `~${command}~`,
})
);
} catch (error) {
message.channel.send(`:x: **${error.message}**`);
}
}
if (command == 'queue' || command == 'q') {
try {
const queue = distube.getQueue(message);
queue
? await message.channel.send(
`:asterisk: Current queue: (Total songs in queue: ${queue.songs.length})\n` +
queue.songs
.map((song, id) =>
id < 15
? `**${id + 1}**. [${song.name}] - \`${
song.formattedDuration
}\``
: ''
)
.join('\n')
)
: await message.channel.send(`:x: **No current queue available**`);
} catch (error) {
message.channel.send(`:x: **${error.message}**`);
}
}
if (command == 'playing' || command === 'pl') {
try {
const nameSong = await client.user.presence.activities.map(
(activitie) => activitie.name
);
nameSong != `${PREFIX}help`
? await message.channel.send(
embedBoilerplate({
title: `:musical_note: Comand: Playing`,
description: `=> Playing: ${nameSong}`,
color: 'GREEN',
footer: `~${command}~`,
})
)
: await message.channel.send(
embedBoilerplate({
title: `:musical_note: Comand: Playing`,
description: `=> Playing: None`,
color: 'RED',
footer: `~${command}~`,
})
);
} catch (error) {
message.channel.send(`:x: **${error.message}**`);
}
}
});
distube
.on('playSong', (queue, song) => {
queue.textChannel.send(`:arrow_forward: Playing \`${song.name}\``);
song ? presence(song.name) : presence();
})
.on('finishSong', () => presence());
client.login(process.env.DISCORD_BOT_TOKEN);
// V0.1.1