summaryrefslogtreecommitdiff
path: root/discord.js
blob: a741477de0bb7d3df8760d366b436fca984e0d30 (plain)
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
function startDiscord() {
    try {
        const { Client, GatewayIntentBits } = require('discord.js');
        const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] });

        client.on('ready', () => {
            console.log(`Logged in as ${client.user.tag}!`);
        });

        function send(channel, text) {
            channel.send({
                embeds: [
                    {
                        description: text
                    }
                ]
            })
        }

        client.on('messageCreate', (msg) => {
            if (!msg.guild || msg.author.bot) return;

            let message = msg.content;

            if (message.startsWith(".") && !message.startsWith("..") && message.trim() !== "." && message.trim() !== ".c." && !message.trim().startsWith(".c.") && !message.trim().startsWith(".❤️")) {
                let command;

                try {
                    command = message.replaceAll(/ +/g, " ");
                    if (command.startsWith(". ")) command = "." + command.substring(2);
                    command = command.split(" ")[0].substring(1).replaceAll("/", "-");
                    let parameter = message.split(" ").splice(1).join(" ");

                    require('./handler')({
                        command,
                        parameter,
                        source: "discord",
                        message: msg,
                        channel: msg.channel,
                        client,
                        discordSend: send
                    });
                } catch (e) {
                    send(msg.channel, "❓ Hmm, something isn't quite right! I was trying to process your message and something wrong happened. I think you need to report this so it can be fixed!\n\n```plaintext\n" + e.stack + "\n```");
                }
            } else if (message.includes("<@" + client.user.id + ">")) {
                send(msg.channel, "👋 Hello! I think you forgot my prefix is `.`, use `.help` to get help.");
            }
        });

        client.login(require('./credentials.json').discord);
    } catch (e) {
        setTimeout(() => {
            startDiscord();
        }, 300000);
    }
}

startDiscord();