This repository has been archived by the owner on Jul 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
69 lines (53 loc) · 2.16 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
const fs = require('node:fs');
const path = require('node:path');
const { Client, Collection, Events, GatewayIntentBits, Partials, EmbedBuilder } = require('discord.js');
require("dotenv").config()
const token = process.env.BOT_TOKEN
const { replyWeapon } = require("./commands/damage.js")
const { replyArmour } = require("./commands/armour.js")
const WeaponDamages = JSON.parse(fs.readFileSync('damage.json'))
const express = require("express");
const { log } = require('node:console');
const app = express();
const port = 8080;
app.get("/", function (req, res) {
res.send("Bot currently running!");
});
app.listen(port, function () {
console.log(`App listening on port ${port}!`);
});
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent
],
partials: [Partials.Message, Partials.Channel]
});
client.cooldowns = new Collection();
client.once(Events.ClientReady, c => {
console.log(`Ready! Logged in as ${c.user.tag}`);
});
client.on(Events.MessageCreate, async message => {
let fullMessage
if (message.partial) {
await message.fetch()
.then(m => {
fullMessage = m.content.toLowerCase();
})
.catch(error => {
console.log('Something went wrong when fetching the message: ', error);
});
} else {
fullMessage = message.content.toLowerCase();
}
if (!fullMessage.startsWith("?")) return false;
console.log(`${message.author.username}[@${message.author.id}] commanded: ${fullMessage}`)
// cooldown handle
if (fullMessage.startsWith("?attack")) return replyWeapon(message, fullMessage, client, WeaponDamages);
if (fullMessage.startsWith("?weapon")) return replyWeapon(message, fullMessage, client, WeaponDamages);
if (fullMessage.startsWith("?armor")) return replyArmour(message, fullMessage, client, WeaponDamages);
if (fullMessage.startsWith("?armour")) return replyArmour(message, fullMessage, client, WeaponDamages);
return message.reply('Command not found!').catch(error => {console.error(error.message)});
});
client.login(token);