-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpablobot.js
49 lines (39 loc) · 1.3 KB
/
pablobot.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
const { Client, GatewayIntentBits, MessageAttachment } = require("discord.js");
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
],
});
const config = require("./config.json");
const fs = require("fs");
const _ = require("lodash");
// const files = fs
// .readdirSync("./resources/")
// .filter((e) => ['.png','.jpg','.mov','.mp4'].some(extension => e.endsWith(extension)));
const cooldown = new Set();
var pictures = [];
var picturesQueue = [];
client.on("ready", () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on("messageCreate", (msg) => {
if (!msg.content.startsWith(config.command) || msg.author.bot) return;
if (cooldown.has(msg.author.id)) {
msg.channel.send(config.cooldownMessage);
return;
}
cooldown.add(msg.author.id);
setTimeout(() => {
cooldown.delete(msg.author.id);
}, config.cooldownTime);
let picture = picturesQueue.shift();
msg.reply({ files: [picture] });
if (picturesQueue.length == 0) picturesQueue = _.shuffle(pictures);
});
files = _.map(fs.readdirSync('./resources'), (file) => './resources/' + file);
pictures = pictures.concat(files);
picturesQueue = _.shuffle(pictures);
client.login(config.token);