-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
52 lines (44 loc) · 1.81 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
// ================= EXPRESS APP HERE ===================
const express = require("express");
const app = express();
const port = process.env.PORT | 3000;
app.listen(port, () => console.log(`Listening on http://localhost:${port}`));
app.get("/", (req, res) => res.send("Sal-kun is Hosted on Repl.it"))
// ================= DISCORD BOT HERE ===================
console.log("Beep boop! 🤖");
const commandHandler = require("./commands");
require("dotenv").config();
const Discord = require("discord.js");
const client = new Discord.Client();
client.login(`${process.env.BOT_TOKEN}`);
client.on("ready", () => {
console.log("I'm Ready! >.<");
client.user.setStatus("idle");
client.user.setActivity("sal help", {
type: "LISTENING"
});
});
client.on("message", (msg) => {
// If we mention the bot alone i.e. "@Sal-kun Bot" and nothing else, we have botMention.
botMention = (msg.content.startsWith(`<@!${client.user.id}`) || msg.content.startsWith(`<@${client.user.id}`)) && msg.content.endsWith(">");
if (botMention) {
let str =
"Hey looks ike you mentioned me. Well my prefix is sal.\n\n" +
"You can try `sal help` to see the help menu."
const prefixEmbed = new Discord.MessageEmbed()
.setDescription(str)
.setColor("#f89e4f");
msg.channel.send(prefixEmbed);
return;
}
// make evrything lower case and check if it starts with sal.
let content = msg.content.toLowerCase();
if (!(/^sal$/g.test(content) || /^sal /g.test(content))) return;
// parses the content.
const withoutPrefix = msg.content.slice(4);
const split = withoutPrefix.split(/ +/);
const cmd = split[0].toLowerCase();
const args = split.slice(1);
// Send it to command handler.
commandHandler(client, msg, cmd, args);
});