-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiscord.js
56 lines (39 loc) · 1.42 KB
/
discord.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
const Discord = require('discord.js')
const fs = require('fs')
const discordLinksJson = require('./discord_links.json')
let token, channelId
try {
const discordVars = require('./discord_vars.json')
channelId = discordVars.CHANNELID
token = discordVars.TOKEN
} catch {
channelId = process.env.CHANNELID
token = process.env.TOKEN
}
const client = new Discord.Client({ intents: [Discord.GatewayIntentBits.Guilds, Discord.GatewayIntentBits.MessageContent] })
let linkChannel
client.on("ready", async () => {
console.log(`Logged in as ${client.user.tag}!`)
linkChannel = await client.channels.cache.get(channelId)
})
async function getDiscordLink(imageLink){
if(discordLinksJson[imageLink] != undefined){
return discordLinksJson[imageLink]
}
return await linkChannel.send({content: `Link: ${imageLink}`}).then(async sent => { // 'sent' is that message you just sent
try{
let embedLink = await sent.embeds[0].data.thumbnail.proxy_url
embedLink = embedLink.replace(/images-ext-1.discordapp.net/,"media.discordapp.net")
discordLinksJson[imageLink] = embedLink
var json_str = JSON.stringify(discordLinksJson, null, 2)
fs.writeFile("discord_links.json", json_str, function (err) {
if (err) return console.log(err);
})
return embedLink
} catch{
return "Not Found"
}
})
}
client.login(token)
module.exports = { getDiscordLink }