-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
162 lines (145 loc) · 5.36 KB
/
app.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
// jshint esversion:8
// Require the necessary discord.js classes
const { Client, Intents } = require('discord.js');
const { token , guildId } = require('./config.json');
const DisTube = require('distube');
// Create a new client instance
var client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MEMBERS,
Intents.FLAGS.GUILD_BANS,
Intents.FLAGS.GUILD_EMOJIS_AND_STICKERS,
Intents.FLAGS.GUILD_INTEGRATIONS,
Intents.FLAGS.GUILD_WEBHOOKS,
Intents.FLAGS.GUILD_INVITES,
Intents.FLAGS.GUILD_VOICE_STATES,
Intents.FLAGS.GUILD_PRESENCES,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
Intents.FLAGS.GUILD_MESSAGE_TYPING,
Intents.FLAGS.DIRECT_MESSAGES,
Intents.FLAGS.DIRECT_MESSAGE_REACTIONS,
Intents.FLAGS.DIRECT_MESSAGE_TYPING
]
});
const distube = new DisTube.default(client, {
emptyCooldown: 30,
ytdlOptions: {
highWaterMark: 1024*1024*10,
quality: 'highestaudio',
filter: 'audioonly',
dlChunkSize: 0,
}
});
// When the client is ready, run this code (only once)
client.once('ready', () => {
console.log('Ready!');
});
// var connection = null;
var msgObject;
var joined = false;
distube.on('searchNoResult', msg => {
msg.channel.send('No results!');
}).on('error', (text, err) => {
console.error('Distube error', err);
}).on('empty', (err) => {
console.error('Empty error', err);
});
client.on('interactionCreate', async (interaction) => {
if (!interaction.isCommand()) return;
const { commandName } = interaction;
if (commandName === "wakeup") {
// join voice channel
await interaction.reply("Yo!");
const gld = client.guilds.cache.get(guildId);
const member = gld.members.cache.get(interaction.user.id);
var channel = member.voice.channel;
try {
distube.voices.join(channel);
joined = true;
} catch (err) {
await interaction.followUp('No voice channel joined!');
}
} else {
if (!joined) {
await interaction.reply('Wake me up first!');
return;
}
if (commandName === 'stop') {
// kick bot
try {
distube.voices.leave(msgObject);
joined = false;
await interaction.reply('Bye Bye!');
} catch (err) {
console.error('Error catched! - stop', err);
}
} else if (commandName === 'play') {
// play song
const songName = interaction.options.getString('song_name');
await interaction.reply(`Searching for: ${songName}`);
try {
distube.play(msgObject, songName);
} catch (err) {
console.error('Error catched! : play - '+err);
}
} else if (commandName === 'pause') {
// pause song
try {
distube.pause(msgObject);
await interaction.reply('Song paused');
} catch (err) {
await interaction.reply('Song already paused');
console.error('Error catched! : pause - ' + err);
}
} else if (commandName === 'resume') {
// resumes the paused song
try {
distube.resume(msgObject);
await interaction.reply('Song resumed');
} catch (err) {
await interaction.reply('Song already playing');
console.error('Error catched! : resume - '+err);
}
} else if( commandName === 'skip') {
// skips the song
try {
let flag = true; //becomes false if distube skip catches error
await distube.skip(msgObject).catch(async (err) => {
await interaction.reply('Nothing to skip.');
console.error('Error catched! : skip - ' + err);
flag = false;
});
if(flag) await interaction.reply('Song skipped!');
} catch(err) {
console.error('Error catched! : skip - ' + err);
}
} else if (commandName === 'shuffle') {
// gives the list of songs in the queue
try {
distube.shuffle(msgObject);
await interaction.reply('Songs Shuffled!');
} catch (err) {
await interaction.reply('No songs playing.');
console.error('Error catched! : shuffle - ' + err);
}
} else if (commandName === 'repeat') {
const repeatMode = interaction.options.getString('repeat_mode');
try {
let mode = distube.setRepeatMode(msgObject, parseInt(repeatMode));
mode = mode ? mode == 2 ? "Repeat queue" : "Repeat song" : "Off";
await interaction.reply("Set repeat mode to `" + mode + "`");
} catch (err) {
await interaction.reply("Set repeat mode to `" + mode + "`");
console.error('Error catched! : repeat-song - ' + err);
}
}
}
});
//jugaad to use distube with slash commands
client.once('messageCreate', msg => {
msgObject = msg;
});
// Login to Discord with your client's token
client.login(token);