ReferenceError: client is not defined

const PTERO_URL = 'panel.';
const API_KEY = 'hheeh';
const NODES_ENDPOINT = `${PTERO_URL}/api/application/nodes`;
const { Client, Collection, GatewayIntentBits } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds] });


client.on('ready', () => {
    console.log(`Logged in as ${client.user.tag}!`);
    // Set up interval to ping nodes every 5 minutes
    setInterval(pingNodes, 5 * 60 * 1000);
});

client.login('MTIxODM3NTk4OTE0MzQwNDYwNA.G21e3T.BXN5bmAXqXHIAg4-AKvAJp4UHVAxIyGKSbTu6g');

async function pingNodes() {
    try {
        const response = await axios.get(NODES_ENDPOINT, {
            headers: {
                'Authorization': `Bearer ${API_KEY}`
            }
        });
        if (response.status === 200) {
            const nodes = response.data.data;
            const onlineNodes = nodes.filter(node => node.attributes.is_online);
            updateEmbed(onlineNodes);
        }
    } catch (error) {
        console.error('Error fetching nodes:', error.message);
    }
}

function updateEmbed(onlineNodes) {
    const embed = new Discord.MessageEmbed()
        .setColor(onlineNodes.length > 0 ? 'GREEN' : 'RED')
        .setTitle('Node Status')
        .setDescription(onlineNodes.length > 0 ? 'All nodes are online' : 'No nodes are online')
        .addField('Online Nodes:', onlineNodes.map(node => node.attributes.name).join('\n') || 'None');
    
    const channel = client.channels.cache.get('1128825813991706655'); // Replace with your channel ID
    if (channel) {
        channel.send(embed)
            .then(() => console.log('Node status updated'))
            .catch(console.error);
    } else {
        console.error('Channel not found');
    }
}


Node.js v21.6.2
PS C:\Users\clou1\Downloads\archive-2024-03-16T014232Z> node .
C:\Users\clou1\Downloads\archive-2024-03-16T014232Z\index.js:5
client.on('ready', () => {
^

ReferenceError: client is not defined
at Object.<anonymous> (C:\Users\clou1\Downloads\archive-2024-03-16T014232Z\index.js:5:1)
at Module._compile (node:internal/modules/cjs/loader:1378:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1437:10)
at Module.load (node:internal/modules/cjs/loader:1212:32)
at Module._load (node:internal/modules/cjs/loader:1028:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:142:12)
at node:internal/main/run_main_module:28:49

Node.js v21.6.2
PS C:\Users\clou1\Downloads\archive-2024-03-16T014232Z> node .
C:\Users\clou1\Downloads\archive-2024-03-16T014232Z\index.js:5
client.on('ready', () => {
^

ReferenceError: client is not defined
at Object.<anonymous> (C:\Users\clou1\Downloads\archive-2024-03-16T014232Z\index.js:5:1)
at Module._compile (node:internal/modules/cjs/loader:1378:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1437:10)
at Module.load (node:internal/modules/cjs/loader:1212:32)
at Module._load (node:internal/modules/cjs/loader:1028:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:142:12)
at node:internal/main/run_main_module:28:49
Was this page helpful?