-
Notifications
You must be signed in to change notification settings - Fork 1
/
bot.js
93 lines (72 loc) · 3.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
const Discord = require('discord.js')
const client = new Discord.Client()
client.on('ready', () => {
console.log("Connected as " + client.user.tag)
client.user.setActivity(" Fucking my own life")
client.guilds.cache.forEach((guild) => {
console.log(" - " + guild.name)
guild.channels.cache.forEach((channel) => {
console.log(` -- ${channel.name} (${channel.type}) - ${channel.id}`)
})
// General : 827774188638175256
})
let generalChannel = client.channels.cache.get("827774188638175256")
const attachment = new Discord.MessageAttachment("https://cdn.searchenginejournal.com/wp-content/uploads/2019/12/how-to-execute-a-link-conversion-strategy-5df792498b991-760x400.png ")
generalChannel.send(attachment)
generalChannel.send("Aur Lamdo!!")
})
client.on('message', (receivedMessage) => {
// Prevent bot from responding to its own messages
if (receivedMessage.author == client.user) {
return
}
//receivedMessage.channel.send("Message received from " + receivedMessage.author.toString() + ": " + receivedMessage.content)
//receivedMessage.react("🖕")
if (receivedMessage.content.startsWith("!")) {
processCommand(receivedMessage)
}
})
function processCommand(receivedMessage) {
let fullCommand = receivedMessage.content.substr(1) // Remove the leading exclamation mark
let splitCommand = fullCommand.split(" ") // Split the message up in to pieces for each space
let primaryCommand = splitCommand[0] // The first word directly after the exclamation is the command
let arguments = splitCommand.slice(1) // All other words are arguments/parameters/options for the command
console.log("Command received: " + primaryCommand)
console.log("Arguments: " + arguments) // There may not be any arguments
if (primaryCommand == "help") {
helpCommand(arguments, receivedMessage)
} else if (primaryCommand == "multiply") {
multiplyCommand(arguments, receivedMessage)}
else if (primaryCommand == "ping") {
pingCommand(arguments, receivedMessage)
}
else {
receivedMessage.channel.send("I don't understand the command. Try `!help` or `!multiply`")
}
}
function helpCommand(arguments, receivedMessage) {
if (arguments.length > 0) {
receivedMessage.channel.send("It looks like you might need help with " + arguments)
} else {
receivedMessage.channel.send("I'm not sure what you need help with. Try `!help [topic]`")
}
}
function multiplyCommand(arguments, receivedMessage) {
if (arguments.length < 2) {
receivedMessage.channel.send("Not enough values to multiply. Try `!multiply 2 4 10` or `!multiply 5.2 7`")
return
}
let product = 1
arguments.forEach((value) => {
product = product * parseFloat(value)
})
receivedMessage.channel.send("The product of " + arguments + " multiplied together is: " + product.toString())
}
function pingCommand(arguments, receivedMessage) {
receivedMessage.channel.send("!pong")
}
// Get your bot's secret token from:
// https://discordapp.com/developers/applications/
// Click on your application -> Bot -> Token -> "Click to Reveal Token"
bot_secret_token = "ODI3NzczNzY0NTk4NDk3MzIx.YGf6ZA.0_BG9GFQto4aNwg1idPkHHVMwGY"
client.login(bot_secret_token)