Update to discordjs 14

This commit is contained in:
Hirzi
2022-11-02 12:21:12 +00:00
parent 3d0512c332
commit 623d0a611c
5 changed files with 59 additions and 41 deletions

View File

@@ -11,7 +11,13 @@
PteroStats adalah bot yang dirancang untuk memeriksa status panel pterodactyl dan dikirim ke server discord
## Contoh
<img alt="Example" src="https://cdn.discordapp.com/attachments/988796533430448148/991520721467613224/example.gif" width="200"/>
- Test Panel
<img alt="Example" src="https://cdn.discordapp.com/attachments/988796533430448148/991520721467613224/example.gif" width="200"/>
- [Calvs Cloud](https://discord.gg/ssCQjhrBJN)
<img alt="Calvs Cloud" src="https://media.discordapp.net/attachments/819757140155564062/1037330231511498822/unknown.png?width=436&height=499" width="200">
## Instalasi
1. [Mendapatkan apikey dari pterodactyl](#mendapatkan-apikey-dari-pterodactyl)

View File

@@ -11,7 +11,13 @@
PteroStats is a bot designed to check Pterodactyl Panel and Nodes status and post it to your discord server
## Example
<img alt="Example" src="https://cdn.discordapp.com/attachments/988796533430448148/991520721467613224/example.gif" width="200"/>
- Test Panel
<img alt="Example" src="https://cdn.discordapp.com/attachments/988796533430448148/991520721467613224/example.gif" width="200"/>
- [Calvs Cloud](https://discord.gg/ssCQjhrBJN)
<img alt="Calvs Cloud" src="https://media.discordapp.net/attachments/819757140155564062/1037330231511498822/unknown.png?width=436&height=499" width="200">
## Installation
1. [Getting apikey from pterodactyl](#getting-apikey-from-pterodactyl)

View File

@@ -1,4 +1,4 @@
const { MessageEmbed, Formatters, MessageActionRow, MessageButton, MessageAttachment } = require('discord.js')
const { EmbedBuilder, time, ActionRowBuilder, ButtonBuilder, AttachmentBuilder, ButtonStyle } = require('discord.js')
const chalk = require('chalk')
module.exports = async function postStatus(client, panel, nodes) {
@@ -21,7 +21,7 @@ module.exports = async function postStatus(client, panel, nodes) {
messages = null
}
const embed = new MessageEmbed()
const embed = new EmbedBuilder()
let text = ''
let desc = ''
@@ -31,7 +31,7 @@ module.exports = async function postStatus(client, panel, nodes) {
const files = []
if (client.config.message.content) content = client.config.message.content
if (client.config.message.attachment) files.push(new MessageAttachment(client.config.message.attachment))
if (client.config.message.attachment) files.push(new AttachmentBuilder(client.config.message.attachment))
if (client.config.embed.title) embed.setTitle(client.config.embed.title)
if (client.config.embed.description) desc = client.config.embed.description + '\n'
@@ -105,8 +105,9 @@ module.exports = async function postStatus(client, panel, nodes) {
})
stats.then(async () => {
const format = await Formatters.time(new Date(Date.now() + client.config.refresh * 1000), 'R')
const format = await time(new Date(Date.now() + client.config.refresh * 1000), 'R')
embed.setDescription(desc.replaceAll('{{time}}', format) + '\n**Nodes Stats [' + Math.floor(nodes.length - blacklist) + ']**' + text)
const EmbedFields = []
if (client.config.panel_resource.enable) {
let stats = '**Status:** ' + String(panel.status).replace('true', client.config.status.online).replace('false', client.config.status.offline) + '\n\n'
@@ -114,53 +115,54 @@ module.exports = async function postStatus(client, panel, nodes) {
if (client.config.panel_resource.users) stats = stats + 'Users: ' + String(panel.total_users).replace('-1', '`Unknown`') + '\n'
if (client.config.panel_resource.servers) stats = stats + 'Servers: ' + String(panel.total_servers).replace('-1', '`Unknown`')
embed.addField('Panel Stats', stats)
EmbedFields.push({ name: 'Panel Stats', value: stats })
}
if (client.config.embed.field.enable) embed.addField(client.config.embed.field.title, client.config.embed.field.description.replaceAll('{{time}}', format))
if (client.config.embed.field.enable) EmbedFields.push({ name: client.config.embed.field.title, value: client.config.embed.field.description.replaceAll('{{time}}', format) })
if (client.config.embed.timestamp) embed.setTimestamp()
if (EmbedFields.length > 0) embed.addFields(EmbedFields)
const row = []
if (client.config.button.enable) {
const button = new MessageActionRow
const button = new ActionRowBuilder
if (client.config.button.btn1.label.length !== 0 && client.config.button.btn1.url.length !== 0) {
button.addComponents(
new MessageButton()
new ButtonBuilder()
.setLabel(client.config.button.btn1.label)
.setStyle('LINK')
.setStyle(ButtonStyle.Link)
.setURL(client.config.button.btn1.url)
)
}
if (client.config.button.btn2.label.length !== 0 && client.config.button.btn2.url.length !== 0) {
button.addComponents(
new MessageButton()
new ButtonBuilder()
.setLabel(client.config.button.btn2.label)
.setStyle('LINK')
.setStyle(ButtonStyle.Link)
.setURL(client.config.button.btn2.url)
)
}
if (client.config.button.btn3.label.length !== 0 && client.config.button.btn3.url.length !== 0) {
button.addComponents(
new MessageButton()
new ButtonBuilder()
.setLabel(client.config.button.btn3.label)
.setStyle('LINK')
.setStyle(ButtonStyle.Link)
.setURL(client.config.button.btn3.url)
)
}
if (client.config.button.btn4.label.length !== 0 && client.config.button.btn4.url.length !== 0) {
button.addComponents(
new MessageButton()
new ButtonBuilder()
.setLabel(client.config.button.btn4.label)
.setStyle('LINK')
.setStyle(ButtonStyle.Link)
.setURL(client.config.button.btn4.url)
)
}
if (client.config.button.btn5.label.length !== 0 && client.config.button.btn5.url.length !== 0) {
button.addComponents(
new MessageButton()
new ButtonBuilder()
.setLabel(client.config.button.btn5.label)
.setStyle('LINK')
.setStyle(ButtonStyle.Link)
.setURL(client.config.button.btn5.url)
)
}

View File

@@ -7,8 +7,8 @@ if (Number(process.version.split('.')[0]) < 16) {
}
if (fs.existsSync('./node_modules')) {
const check = require('./node_modules/discord.js/package.json')
if (Number(check.version.split('.')[0]) !== 13) {
console.log('Invalid Discord.JS Version!, Please use Discord.JS 13.x')
if (Number(check.version.split('.')[0]) !== 14) {
console.log('Invalid Discord.JS Version!, Please use Discord.JS 14.x')
process.exit()
}
} else {
@@ -25,26 +25,30 @@ if (fs.existsSync('./node_modules')) {
}
}
const path = require('node:path');
const chalk = require('chalk');
const yaml = require('js-yaml');
const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
const { Client, GatewayIntentBits } = require('discord.js');
const config = yaml.load(fs.readFileSync('./config.yml', 'utf8'));
client.config = config
const eventFiles = fs.readdirSync('./events').filter(file => file.endsWith('.js'));
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
const eventsPath = path.join(__dirname, 'events');
const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js'));
for (const file of eventFiles) {
const event = require(`./events/${file}`);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args));
} else {
client.on(event.name, (...args) => event.execute(...args));
}
const filePath = path.join(eventsPath, file);
const event = require(filePath);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args));
} else {
client.on(event.name, (...args) => event.execute(...args));
}
}
if (client.config.token.startsWith('Put')) {
if (client.config.token.startsWith('Put') || client.config.token.length < 1) {
console.log(chalk.cyan('[PteroStats]') + chalk.red(' Err! Invalid Discord Bot Token'))
process.exit()
}

View File

@@ -1,24 +1,24 @@
{
"name": "pterostats",
"version": "v2.0.0",
"version": "v3.0.0",
"description": "PteroStats is a bot designed to check Pterodactyl Panel and Nodes status and post it to your discord server",
"license": "MIT",
"repository": "HirziDevs/PteroStats",
"homepage": "https://pterostats.hirzidevs.net",
"bugs": {
"email": "hirzidevs@gmail.com",
"url": "https://github.com/HirziDevs/PteroStats"
"email": "hirzidevs@gmail.com",
"url": "https://github.com/HirziDevs/PteroStats"
},
"scripts": {
"start": "node index.js"
"start": "node index.js"
},
"dependencies": {
"axios": "^0.27.2",
"chalk": "4.1.1",
"discord.js": "^13.8.1",
"js-yaml": "^4.1.0"
"axios": "^0.27.2",
"chalk": "4.1.1",
"discord.js": "^14.6.0",
"js-yaml": "^4.1.0"
},
"engines": {
"node": "^16.x"
"node": "^16.x"
}
}