-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.js
More file actions
45 lines (37 loc) · 1.39 KB
/
bot.js
File metadata and controls
45 lines (37 loc) · 1.39 KB
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
const { Client, GatewayIntentBits, ActivityType, Events } = require('discord.js');
const client = new Client({ intents: [ GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages ] });
require('dotenv').config();
client.login(process.env.DISCORD_TOKEN);
const { cpu } = require('node-os-utils');
const os = require('os');
const commands = {
trigger: /%(t|trigger)/i,
ping: /%(p|ping)/i
};
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}`);
setInterval(update, 1000);
});
client.on(Events.MessageCreate, message => {
const text = message.content;
if (text.match(commands.trigger))
message.channel.send("`Host is up.`");
if (text.match(commands.ping)) {
message.channel.send("Pinging...").then(msg => {
const ping = msg.createdTimestamp - message.createdTimestamp;
msg.edit(`Ping: ${ping}`)
});
}
});
const update = async () => {
const freeMem = Math.floor(os.freemem() / 1024 / 1024);
const totalMem = Math.floor(os.totalmem() / 1024 / 1024);
const usedMem = Math.floor(totalMem - freeMem);
const cpuPercentage = Math.floor(await cpu.usage());
client.user.setPresence({
activities: [ {
name: `RAM: ${usedMem}MB/${totalMem}MB, CPU: ${cpuPercentage}%`,
type: ActivityType.Watching
} ], status: 'idle'
});
}