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');
}
}
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
6 Replies
d.js toolkit
d.js toolkit•3mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
-Carlos👑
-Carlos👑•3mo ago
reset your token
china charlie morningstar
i just did
d.js docs
d.js docs•3mo ago
:mdn: Scope The scope is the current context of execution in which values and expressions are "visible" or can be referenced. If a variable or expression is not in the current scope, it will not be available for use. Scopes can also be layered in a hierarchy, so that child scopes have access to parent scopes, but not vice versa. - ReferenceError: "x" is not defined: learn more - TypeError: Cannot read properties of undefined/null (reading "x"): learn more
china charlie morningstar
dont understand
Unknown User
Unknown User•3mo ago
Message Not Public
Sign In & Join Server To View