-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.js
More file actions
39 lines (35 loc) · 1.17 KB
/
bot.js
File metadata and controls
39 lines (35 loc) · 1.17 KB
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
const Discord = require('discord.js');
const rn = require('random-number');
const client = new Discord.Client();
require('dotenv').config()
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
var randomOptions = {
min: 1
, max: 2
, integer: true
};
client.on('message', message => {
if (message.content === '!audio') {
if (message.member.voiceChannel) {
var random = rn(randomOptions);
console.log("sending audio number " + random);
message.member.voiceChannel.join()
.then(connection => {
const dispatcher = connection.playFile('./aud/' + random + '.mp3');
dispatcher.on('end', () => {
setTimeout(function () {
message.member.voiceChannel.leave();
}, 1000)
});
})
.catch(console.log);
} else {
message.reply("You need to be in a voice channel for this to work.");
}
} else if (message.content === "!help") {
message.reply("!audio -> plays a random audio.");
}
});
client.login(process.env.DISCORD_BOT_TOKEN);