-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
56 lines (45 loc) · 1.42 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
const Discord = require("discord.js");
const config = require("./config.json");
const client = new Discord.Client();
const prefix = "!";
client.on("message", function(message) {
if (message.author.bot) return;
if (!message.content.startsWith(prefix)) return;
const commandBody = message.content.slice(prefix.length);
const args = commandBody.split(' ');
const command = args.shift().toLowerCase();
if (command === "ping") {
const timeTaken = Date.now() - message.createdTimestamp;
message.reply(`Pong! This message had a latency of ${timeTaken}ms.`);
}
else if (command === "add") {
var link = "";
var title = "";
var linkindex;
for (i = 0; i < args.length; i++) {
if (args[i].startsWith("http") || args[i].startsWith("www")) {
link = args[i];
linkindex = i;
break
}
else {
title = title + " " + args[i];
}
}
if ((args.length - 1) == (linkindex + 1))
{
var username = args[linkindex + 1];
var author = client.users.cache.find(u => u.tag === username).id;
}
else
{
var author = message.author.id;
}
if (args.length >= 2) {
message.delete({ timeout: 100 });
client.channels.cache.get('750802687280414771').send(`${title}: ${link}
Thank you <@${author}>!`);
}
}
});
client.login(config.BOT_TOKEN);