-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
89 lines (66 loc) · 3.5 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
/*
██╗ ██╗ █████╗ ██╗ ██╗ ██╗ ██████╗ ██╗ ██╗██████╗ ██╗██████╗
██║ ██║██╔══██╗██║ ██║ ██╔╝██╔═══██╗██║ ██║██╔══██╗ ██╔╝╚════██╗
██║ █╗ ██║███████║██║ █████╔╝ ██║ ██║██║ ██║██║ ██║ ██╔╝ █████╔╝
██║███╗██║██╔══██║██║ ██╔═██╗ ██║ ██║██║ ██║██║ ██║ ╚██╗ ╚═══██╗
╚███╔███╔╝██║ ██║███████╗██║ ██╗╚██████╔╝╚██████╔╝██████╔╝ ╚██╗██████╔╝
╚══╝╚══╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚═╝╚═════╝
github.com/walkoud
please leave a star <3
*/
const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
const axios = require('axios');
const fs = require('fs');
const MediaDownloader = require('media-downloader-ez');
let config = require("./config.json");
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('messageCreate', message => {
if (message.author.bot) return;
const args = message.content.slice(1).trim().split(/ +/);
const command = args.shift().toLowerCase();
if (command === 'ping') {
message.reply('Pong!');
}
if (command === config.commandname) { // <============= HERE DOWNLOAD COMMAND
if (config.onlyONEchannel && config.channelid !== message.channel.id) return message.reply("Only in channel <#" + config.channelid + ">").then((m) => { deleteMessage(m) })
deleteMessage(message);
let videoUrl = args[0];
if (!videoUrl) return message.reply("Please specify a video URL...").then((m) => { deleteMessage(m) });
if(MediaDownloader.isVideoLink(videoUrl)){
message.channel.send('downloading...').then(async (m) => {
try {
let attachment
if(message.content.includes("crop")){
attachment = await MediaDownloader(videoUrl, {autocrop: true});
} else {
attachment = await MediaDownloader(videoUrl, {autocrop: config.autoCropVideos});
}
message.channel.send({ content: `Downloaded by: \`${message.author.username}\``, files: [attachment] })
deleteMessage(m, 0)
} catch (error) {
console.log(error)
m.edit("Error downloading")
deleteMessage(m, 3000)
}
})
}
else {
message.reply("Please specify a video URL from Instagram, YouTube, X, tiktok, facebook...").then((m) => { deleteMessage(m) })
}
}
});
function deleteMessage(message, howlong) {
if (howlong) {
setTimeout(() => {
message.delete();
}, howlong);
} else {
setTimeout(() => {
message.delete();
}, 3000);
}
}
client.login(config.token);