-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.js
75 lines (57 loc) · 2.3 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
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
const Discord = require("discord.js")
const client = new Discord.Client();
const config = require("./config.json");
client.on('ready', (...args) => {
var s = "s";
console.log(`Serving: `);
console.log(` ${client.guilds.cache.size} servers`);
console.log(` ${client.channels.cache.size} channels`);
console.log(` ${client.users.cache.size} users`);
console.log(`\nServers: `);
client.guilds.cache.forEach(guild => {
console.log(` - ${guild.name} (ID: ${guild.id})`);
})
console.log(`\nBot Info:`)
console.log(` Tag: ${client.user.tag}`);
console.log("\nPress Ctrl + C to Quit\n");
})
client.on('message', message => {
//check if message starts with prefix in config
if (message.content.indexOf(config.prefix) !== 0) return;
//seperate the prefix, comamnd, and arguments
const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
const command = args.shift().toLowerCase();
//put together args cause right now its an array
var argsContent = args.join(' ');
//check if command is the command in the config
if (command != config.command) return;
//just send args in requested channels/DMs
var message = `**${message.author.tag} (<@${message.author.id}>)** has inquired about: ${argsContent}`;
if (config.sendToChannel) {
if (config.channelId == "" || config.channelId == undefined) {
console.log(`Error: Missing Channel ID`);
}
client.channels.fetch(config.channelId)
.then(channel => {
channel.send(message)
.catch(e => console.error(`Error sending message in channel: ${e.message}`));
})
.catch(e => {
console.error(`Could not find channel: ${e.message}`);
})
}
if (config.dmToUser) {
if (config.userId == "" || config.userId == undefined) {
console.log(`Error: Missing User ID`);
}
client.users.fetch(config.userId)
.then(user => {
user.send(message)
.catch(e => console.error(`Error sending message to user: ${e.message}`));
})
.catch(e => {
console.error(`Could not find user: ${e.message}`);
})
}
});
client.login(config.token);