-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
121 lines (115 loc) · 4.28 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
require('dotenv').config()
const { DisTube } = require('distube')
const Discord = require('discord.js')
const client = new Discord.Client({
intents: [
Discord.Intents.FLAGS.GUILDS,
Discord.Intents.FLAGS.GUILD_MESSAGES,
Discord.Intents.FLAGS.GUILD_VOICE_STATES
]
})
const fs = require('fs')
const config = require('./config.json')
const { SpotifyPlugin } = require('@distube/spotify')
const { SoundCloudPlugin } = require('@distube/soundcloud')
const { YtDlpPlugin } = require('@distube/yt-dlp')
client.config = require('./config.json')
client.distube = new DisTube(client, {
leaveOnStop: false,
emitNewSongOnly: true,
emitAddSongWhenCreatingQueue: false,
emitAddListWhenCreatingQueue: false,
plugins: [
new SpotifyPlugin({
emitEventsAfterFetching: true
}),
new SoundCloudPlugin(),
new YtDlpPlugin()
],
youtubeDL: false
})
client.commands = new Discord.Collection()
client.aliases = new Discord.Collection()
client.emotes = config.emoji
fs.readdir('./commands/', (err, files) => {
if (err) return console.log('Could not find any commands!')
const jsFiles = files.filter(f => f.split('.').pop() === 'js')
if (jsFiles.length <= 0) return console.log('Could not find any commands!')
jsFiles.forEach(file => {
const cmd = require(`./commands/${file}`)
console.log(`Loaded ${file}`)
client.commands.set(cmd.name, cmd)
if (cmd.aliases) cmd.aliases.forEach(alias => client.aliases.set(alias, cmd.name))
})
})
client.on('ready', () => {
console.log(`${client.user.tag} is ready to play music.`)
})
client.on('messageCreate', async message => {
if (message.author.bot || !message.guild) return
const prefix = process.env.PREFIX
if (!message.content.startsWith(prefix)) return
const args = message.content.slice(prefix.length).trim().split(/ +/g)
const command = args.shift().toLowerCase()
const cmd = client.commands.get(command) || client.commands.get(client.aliases.get(command))
if (!cmd) return
if (cmd.inVoiceChannel && !message.member.voice.channel) {
return message.channel.send(`${client.emotes.error} | You must be in a voice channel!`)
}
try {
cmd.run(client, message, args)
} catch (e) {
console.error(e)
message.channel.send(`${client.emotes.error} | Error: \`${e}\``)
}
})
const status = queue =>
`Volume: \`${queue.volume}%\` | Filter: \`${queue.filters.join(', ') || 'Off'}\` | Loop: \`${
queue.repeatMode ? (queue.repeatMode === 2 ? 'All Queue' : 'This Song') : 'Off'
}\` | Autoplay: \`${queue.autoplay ? 'On' : 'Off'}\``
client.distube
.on('playSong', (queue, song) =>
queue.textChannel.send(
`${client.emotes.play} | Playing \`${song.name}\` - \`${song.formattedDuration}\`\nRequested by: ${
song.user
}\n${status(queue)}`
)
)
.on('addSong', (queue, song) =>
queue.textChannel.send(
`${client.emotes.success} | Added ${song.name} - \`${song.formattedDuration}\` to the queue by ${song.user}`
)
)
.on('addList', (queue, playlist) =>
queue.textChannel.send(
`${client.emotes.success} | Added \`${playlist.name}\` playlist (${
playlist.songs.length
} songs) to queue\n${status(queue)}`
)
)
.on('error', (channel, e) => {
channel.send(`${client.emotes.error} | An error encountered: ${e.toString().slice(0, 1974)}`)
console.error(e)
})
.on('empty', channel => channel.send('Voice channel is empty! Leaving the channel...'))
.on('searchNoResult', (message, query) =>
message.channel.send(`${client.emotes.error} | No result found for \`${query}\`!`)
)
.on('finish', queue => queue.textChannel.send('Finished!'))
// // DisTubeOptions.searchSongs = true
// .on("searchResult", (message, result) => {
// let i = 0
// message.channel.send(
// `**Choose an option from below**\n${result
// .map(song => `**${++i}**. ${song.name} - \`${song.formattedDuration}\``)
// .join("\n")}\n*Enter anything else or wait 60 seconds to cancel*`
// )
// })
// .on("searchCancel", message => message.channel.send(`${client.emotes.error} | Searching canceled`))
// .on("searchInvalidAnswer", message =>
// message.channel.send(
// `${client.emotes.error} | Invalid answer! You have to enter the number in the range of the results`
// )
// )
// .on("searchDone", () => {})
client.login(process.env.TOKEN)