-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.js
42 lines (36 loc) · 1.12 KB
/
bot.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
require("dotenv").config();
const { Client, Intents } = require("discord.js");
const request = require(`request`);
const fs = require(`fs`);
const path = require("path");
const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.DIRECT_MESSAGES,
],
partials: ["MESSAGE", "CHANNEL", "REACTION"],
});
client.on("messageCreate", (message) => {
if (message.channel.type == "DM" && message.author.id != client.user.id) {
if (message.attachments.first()) {
message.attachments.forEach((attachment) => {
download(
attachment.url,
path.resolve(process.env.BASE_PATH, attachment.name)
);
});
message.reply("Habs danke");
console.log("Downloaded " + message.attachments.size + " files");
} else {
message.reply("Du musst schon eine Datei senden lmao, imagine cringe");
}
}
});
client.login(process.env.TOKEN);
client.on("ready", () => {
console.log(`Logged in as ${client.user.tag}!`);
});
function download(url, path) {
request.get(url).on("error", console.error).pipe(fs.createWriteStream(path));
}