-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
61 lines (52 loc) · 1.24 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
var request = require("request-promise");
const Discord = require("discord.js");
const bot = new Discord.Client();
const TOKEN = "discord token";
bot.login(TOKEN);
bot.on("ready", () => {
console.info(`Logged in as ${bot.user.tag}!`);
});
bot.on("message", async (msg) => {
var messageType
if (msg.author.username !== 'Line Bot') {
if (msg.attachments.size > 0) {
console.log(msg.attachments)
const url = msg.attachments.map(item => {
console.log(item)
return item.url
})
messageType = {
type: "image",
originalContentUrl: url[0],
previewImageUrl: url[0]
}
} else {
messageType = {
type: "text",
text: `[${msg.author.username}] ${msg.content}`,
}
}
const userID = 'Users ID'
await Promise.all(
userID.map(async (id) => {
await request(
{
headers: {
"Content-Type": "application/json",
Authorization:
"Bearer line access token",
},
uri: "https://api.line.me/v2/bot/message/push",
method: "POST",
body: JSON.stringify({
to: id,
messages: [
messageType
]
})
}
);
})
)
}
});