-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
82 lines (64 loc) · 2.75 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
const token = require("./token")
const Discord = require('discord.js')
const help = require("./help")
const multiply = require("./multiply")
const react = require("./react")
const countdown = require("./countdown")
const client = new Discord.Client()
client.once('ready', () => {
console.log('the bot is online!')
client.user.setActivity('with Javascript', {type: "PLAYING"})
//list all servers the bot is connected to
console.log('\nServers:')
client.guilds.cache.forEach((guild) => {
console.log(' - '+guild.name)
//list all channels in the server
guild.channels.cache.forEach((channel) => {
console.log(` -- ${channel.name} (${channel.type}) - ${channel.id}`)
})
})
// //send a message to a specific channel
// var generalChannel = client.channels.cache.get('750373912738791567')
// generalChannel.send('hello world')
// })
// client.on('message', (receivedMessage) => {
// //prevent bot from responding to its own message
// if(receivedMessage.author == client.user) {
// return
// }
// //bot responds to all messages in ALL channels in the server
// receivedMessage.channel.send("Message received from " + receivedMessage.author.toString() + ": " + receivedMessage.content)
// //bot responds to all messages in ALL channels it has been tagged in
// if(receivedMessage.content.includes(client.user.toString())) {
// receivedMessage.channel.send("Message received from " + receivedMessage.author.toString() + ": " + receivedMessage.content)
// }
client.on('message', (receivedMessage) => {
if(receivedMessage.author == client.user) {
return
}
if(receivedMessage.content.startsWith('!')) {
processCommand(receivedMessage)
}
})
})
function processCommand(receivedMessage) {
let fullCommand = receivedMessage.content.substr(1) //remove the leading/bot identifying character
let splitCommand = fullCommand.split(" ") //split the message up into pieces for each space
let primaryCommand = splitCommand[0] //take the first string from the split
let arguments = splitCommand.slice(1) //all other words are arguments/parameters for the primaryCommand
console.log('command received: ' + primaryCommand)
console.log('Arguments: ' + arguments)
if (primaryCommand == "help") {
help(arguments, receivedMessage)
}
else if (primaryCommand == 'multiply') {
multiply(arguments, receivedMessage)
}
else if (primaryCommand == 'react') {
react(arguments, receivedMessage)
}
else if (primaryCommand == 'countdown') {
countdown(arguments, receivedMessage)
}
}
client.login(token)