embed

const { SlashCommandBuilder } = require('@discordjs/builders');
const { MessageEmbed } = require('discord.js'); // Make sure this import is correct
const axios = require('axios');

module.exports = {
data: new SlashCommandBuilder()
.setName('nodeping')
.setDescription('Ping the nodes to check their status.'),

async execute(interaction) {
try {
const response = await axios.get('https://panel.nauticalmc.net/api/application/nodes', {
headers: {
Authorization: 'Bearer no api key for y',
'Content-Type': 'application/json'
}
});

if (response.status === 200) {
const nodes = response.data.data;
const onlineNodes = nodes.filter(node => node.attributes.is_online);

const embed = new MessageEmbed()
.setTitle('Node Status')
.setDescription(onlineNodes.length > 0 ? 'Some nodes are online!' : 'No nodes are online!')
.setColor(onlineNodes.length > 0 ? 'GREEN' : 'RED');

onlineNodes.forEach(node => {
embed.addField('Online Node', node.attributes.name);
});

await interaction.reply({ embeds: [embed] });
} else {
await interaction.reply('Failed to ping the nodes.');
}
} catch (error) {
console.error('Error pinging the nodes:', error);
await interaction.reply('Error pinging the nodes.');
}
},
};
const { SlashCommandBuilder } = require('@discordjs/builders');
const { MessageEmbed } = require('discord.js'); // Make sure this import is correct
const axios = require('axios');

module.exports = {
data: new SlashCommandBuilder()
.setName('nodeping')
.setDescription('Ping the nodes to check their status.'),

async execute(interaction) {
try {
const response = await axios.get('https://panel.nauticalmc.net/api/application/nodes', {
headers: {
Authorization: 'Bearer no api key for y',
'Content-Type': 'application/json'
}
});

if (response.status === 200) {
const nodes = response.data.data;
const onlineNodes = nodes.filter(node => node.attributes.is_online);

const embed = new MessageEmbed()
.setTitle('Node Status')
.setDescription(onlineNodes.length > 0 ? 'Some nodes are online!' : 'No nodes are online!')
.setColor(onlineNodes.length > 0 ? 'GREEN' : 'RED');

onlineNodes.forEach(node => {
embed.addField('Online Node', node.attributes.name);
});

await interaction.reply({ embeds: [embed] });
} else {
await interaction.reply('Failed to ping the nodes.');
}
} catch (error) {
console.error('Error pinging the nodes:', error);
await interaction.reply('Error pinging the nodes.');
}
},
};
Error pinging the nodes: TypeError: MessageEmbed is not a constructor at Object.execute (/home/container/commands/server/nodepinger.js:23:31) at processTicksAndRejections (node:internal/process/task_queues:95:5) at async Object.execute (/home/container/events/interactionCreate.jjs4)
72 Replies
d.js toolkit
d.js toolkitβ€’9mo 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πŸ‘‘β€’9mo ago
it's EmbedBuilder for v14
π’»π“‡π‘’π’Άπ“€π“Ž
ty let me try Error pinging the nodes: ReferenceError: MessageEmbed is not defined at Object.execute (/home/container/commands/server/nodepinger.js:23:31) at processTicksAndRejections (node:internal/process/task_queues:95:5) at async Object.execute (/home/container/events/interactionCreate.js:16:4) new error
-CarlosπŸ‘‘
-CarlosπŸ‘‘β€’9mo ago
you didn't change it you forgot to change it on your interactionCreate event
-CarlosπŸ‘‘
-CarlosπŸ‘‘β€’9mo ago
^
π’»π“‡π‘’π’Άπ“€π“Ž
:i dont understand wher e
-CarlosπŸ‘‘
-CarlosπŸ‘‘β€’9mo ago
go to your interactionCreate.js file and change MessageEmbed to EmbedBuilder
π’»π“‡π‘’π’Άπ“€π“Ž
ok const { Events } = require('discord.js'); module.exports = { name: Events.InteractionCreate, async execute(interaction) { if (!interaction.isChatInputCommand()) return; const command = interaction.client.commands.get(interaction.commandName); if (!command) { console.error(No command matching ${interaction.commandName} was found.); return; } try { await command.execute(interaction); } catch (error) { console.error(error); if (interaction.replied || interaction.deferred) { await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true }); } else { await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true }); } } }, }; where @-CarlosπŸ‘‘
-CarlosπŸ‘‘
-CarlosπŸ‘‘β€’9mo ago
is that your full code
-CarlosπŸ‘‘
-CarlosπŸ‘‘β€’9mo ago
can you run npm list discord.js on your console wait, did you save the file
-CarlosπŸ‘‘
-CarlosπŸ‘‘β€’9mo ago
are you sure
π’»π“‡π‘’π’Άπ“€π“Ž
yes @-CarlosπŸ‘‘
-CarlosπŸ‘‘
-CarlosπŸ‘‘β€’9mo ago
did you also change it on the const embed = new MessageEmbed() part? also can you stop pinging me
π’»π“‡π‘’π’Άπ“€π“Ž
what am i gonna change it to const embed = new MessageEmbed()
-CarlosπŸ‘‘
-CarlosπŸ‘‘β€’9mo ago
^
π’»π“‡π‘’π’Άπ“€π“Ž
ok const embed = new EmbedBuilder () to that
-CarlosπŸ‘‘
-CarlosπŸ‘‘β€’9mo ago
yeah remove that extra space
π’»π“‡π‘’π’Άπ“€π“Ž
ok Error pinging the nodes: TypeError [ColorConvert]: Unable to convert color to a number. at resolveColor (/home/container/node_modules/discord.js/src/util/Util.js:290:63) at EmbedBuilder.setColor (/home/container/node_modules/discord.js/src/structures/EmbedBuilder.js:23:36) at Object.execute (/home/container/commands/server/nodepinger.js:26:22) at processTicksAndRejections (node:internal/process/task_queues:95:5) at async Object.execute (/home/container/events/interactionCreate.js:16:4) { code: 'ColorConvert' }
-CarlosπŸ‘‘
-CarlosπŸ‘‘β€’9mo ago
embed colors are PascalCase
-CarlosπŸ‘‘
-CarlosπŸ‘‘β€’9mo ago
yeah if you want to use a hex color instead that should work
π’»π“‡π‘’π’Άπ“€π“Ž
Error pinging the nodes: DiscordAPIError[10062]: Unknown interaction at handleErrors (/home/container/node_modules/@discordjs/rest/src/lib/handlers/Shared.ts:148:10) at processTicksAndRejections (node:internal/process/task_queues:95:5) at async BurstHandler.runRequest (/home/container/node_modules/@discordjs/rest/src/lib/handlers/BurstHandler.ts:143:20) at async _REST.request (/home/container/node_modules/@discordjs/rest/src/lib/REST.ts:211:20) at async ChatInputCommandInteraction.reply (/home/container/node_modules/discord.js/src/structures/interfaces/InteractionResponses.js:111:5) at async Object.execute (/home/container/commands/server/nodepinger.js:32:17) at async Object.execute (/home/container/events/interactionCreate.js:16:4) { requestBody: { files: [], json: { type: 4, data: [Object] } }, rawError: { message: 'Unknown interaction', code: 10062 }, code: 10062, status: 404, method: 'POST', url: 'https://discord.com/api/v10/interactions/1218733265435758622/aW50ZXJhY3Rpb246MTIxODczMzI2NTQzNTc1ODYyMjozbDJ1WGxnMWRHaUQxU1p6MHIyUFRqVTR5Z0ZwVnhLbGRYcGJRQU5kQlVQYjk1UXc5SzVndjBJd3NIUHY2WU83TjJMeGhVVUt1YkN5SEJaVzk3U3hreGk3M0QyamhsOEtMUGU0UWlCRlU0RW9sOHVqZUZobVV4NW1ZckNyN09UWg/callback' } DiscordAPIError[10062]: Unknown interaction at handleErrors (/home/container/node_modules/@discordjs/rest/src/lib/handlers/Shared.ts:148:10) at processTicksAndRejections (node:internal/process/task_queues:95:5) at async BurstHandler.runRequest (/home/container/node_modules/@discordjs/rest/src/lib/handlers/BurstHandler.ts:143:20) at async _REST.request (/home/container/node_modules/@discordjs/rest/src/lib/REST.ts:211:20) at async ChatInputCommandInteraction.reply (/home/container/node_modules/discord.js/src/structures/interfaces/InteractionResponses.js:111:5) at async Object.execute (/home/container/commands/server/nodepinger.js:38:13) at async Object.execute (/home/container/events/interactionCreate.js:16:4) { requestBody: { files: [], json: { type: 4, data: [Object] } }, rawError: { message: 'Unknown interaction', code: 10062 }, code: 10062, status: 404, method: 'POST', url: 'https://discord.com/api/v10/interactions/1218733265435758622/aW50ZXJhY3Rpb246MTIxODczMzI2NTQzNTc1ODYyMjozbDJ1WGxnMWRHaUQxU1p6MHIyUFRqVTR5Z0ZwVnhLbGRYcGJRQU5kQlVQYjk1UXc5SzVndjBJd3NIUHY2WU83TjJMeGhVVUt1YkN5SEJaVzk3U3hreGk3M0QyamhsOEtMUGU0UWlCRlU0RW9sOHVqZUZobVV4NW1ZckNyN09UWg/callback' } /home/container/node_modules/@discordjs/rest/src/lib/handlers/Shared.ts:148 throw new DiscordAPIError(data, 'code' in data ? data.code : data.error, status, method, url, requestData); ^ DiscordAPIError[10062]: Unknown interaction at handleErrors (/home/container/node_modules/@discordjs/rest/src/lib/handlers/Shared.ts:148:10) at processTicksAndRejections (node:internal/process/task_queues:95:5) at async BurstHandler.runRequest (/home/container/node_modules/@discordjs/rest/src/lib/handlers/BurstHandler.ts:143:20) at async _REST.request (/home/container/node_modules/@discordjs/rest/src/lib/REST.ts:211:20) at async ChatInputCommandInteraction.reply (/home/container/node_modules/discord.js/src/structures/interfaces/InteractionResponses.js:111:5) at async Object.execute (/home/container/events/interactionCreate.js:22:5) { requestBody: { files: [], json: { type: 4, data: [Object] } }, rawError: { message: 'Unknown interaction', code: 10062 }, code: 10062, status: 404, method: 'POST', url: 'https://discord.com/api/v10/interactions/1218733265435758622/aW50ZXJhY3Rpb246MTIxODczMzI2NTQzNTc1ODYyMjozbDJ1WGxnMWRHaUQxU1p6MHIyUFRqVTR5Z0ZwVnhLbGRYcGJRQU5kQlVQYjk1UXc5SzVndjBJd3NIUHY2WU83TjJMeGhVVUt1YkN5SEJaVzk3U3hreGk3M0QyamhsOEtMUGU0UWlCRlU0RW9sOHVqZUZobVV4NW1ZckNyN09UWg/callback' }
d.js docs
d.js docsβ€’9mo ago
To share long code snippets, use a service like gist, sourcebin, starbin, or similar instead of posting them as large code blocks or files.
-CarlosπŸ‘‘
-CarlosπŸ‘‘β€’9mo ago
show your full code
-CarlosπŸ‘‘
-CarlosπŸ‘‘β€’9mo ago
full code, not full error
π’»π“‡π‘’π’Άπ“€π“Ž
ok
const { SlashCommandBuilder } = require('@discordjs/builders');
const { EmbedBuilder } = require('discord.js'); // Make sure this import is correct
const axios = require('axios');

module.exports = {
data: new SlashCommandBuilder()
.setName('nodeping')
.setDescription('Ping the nodes to check their status.'),

async execute(interaction) {
try {
const response = await axios.get('https://panel.nauticalmc.net/api/application/nodes', {
headers: {
Authorization: 'Bearer no api key for u :0',
'Content-Type': 'application/json'
}
});

if (response.status === 200) {
const nodes = response.data.data;
const onlineNodes = nodes.filter(node => node.attributes.is_online);

const embed = new EmbedBuilder()
.setTitle('Node Status')
.setDescription(onlineNodes.length > 0 ? 'Some nodes are online!' : 'No nodes are online!')
.setColor(onlineNodes.length > 0 ? '#57F287' : '#ED4245');

onlineNodes.forEach(node => {
embed.addField('Online Node', node.attributes.name);
});

await interaction.reply({ embeds: [embed] });
} else {
await interaction.reply('Failed to ping the nodes.');
}
} catch (error) {
console.error('Error pinging the nodes:', error);
await interaction.reply('Error pinging the nodes.');
}
},
};
const { SlashCommandBuilder } = require('@discordjs/builders');
const { EmbedBuilder } = require('discord.js'); // Make sure this import is correct
const axios = require('axios');

module.exports = {
data: new SlashCommandBuilder()
.setName('nodeping')
.setDescription('Ping the nodes to check their status.'),

async execute(interaction) {
try {
const response = await axios.get('https://panel.nauticalmc.net/api/application/nodes', {
headers: {
Authorization: 'Bearer no api key for u :0',
'Content-Type': 'application/json'
}
});

if (response.status === 200) {
const nodes = response.data.data;
const onlineNodes = nodes.filter(node => node.attributes.is_online);

const embed = new EmbedBuilder()
.setTitle('Node Status')
.setDescription(onlineNodes.length > 0 ? 'Some nodes are online!' : 'No nodes are online!')
.setColor(onlineNodes.length > 0 ? '#57F287' : '#ED4245');

onlineNodes.forEach(node => {
embed.addField('Online Node', node.attributes.name);
});

await interaction.reply({ embeds: [embed] });
} else {
await interaction.reply('Failed to ping the nodes.');
}
} catch (error) {
console.error('Error pinging the nodes:', error);
await interaction.reply('Error pinging the nodes.');
}
},
};
umm u there
-CarlosπŸ‘‘
-CarlosπŸ‘‘β€’9mo ago
yeah
d.js docs
d.js docsβ€’9mo ago
Common causes of DiscordAPIError[10062]: Unknown interaction: - Initial response took more than 3 seconds ➞ defer the response *. - Wrong interaction object inside a collector. - Two processes handling the same command (the first consumes the interaction, so it won't be valid for the other instance) * Note: you cannot defer modal or autocomplete value responses
-CarlosπŸ‘‘
-CarlosπŸ‘‘β€’9mo ago
most likely that axios call took more than 3 seconds
-CarlosπŸ‘‘
-CarlosπŸ‘‘β€’9mo ago
it says it here
-CarlosπŸ‘‘
-CarlosπŸ‘‘β€’9mo ago
- Initial response took more than 3 seconds ➞ defer the response *.
π’»π“‡π‘’π’Άπ“€π“Ž
how do i fix async execute(interaction) { try { const response = await axios.get('https://panel.nauticalmc.net/api/application/nodes', { headers: { Authorization: 'Bearer your-api-key', 'Content-Type': 'application/json' } }); like this nvm can u fix it for me @-CarlosπŸ‘‘
-CarlosπŸ‘‘
-CarlosπŸ‘‘β€’9mo ago
you literally just need to defer the reply
π’»π“‡π‘’π’Άπ“€π“Ž
async execute(interaction) { try { await interaction.deferReply(); const response = await axios.get('https://panel.nauticalmc.net/api/application/nodes', { headers: { Authorization: 'Bearer your-api-key', 'Content-Type': 'application/json' } }); like this
-CarlosπŸ‘‘
-CarlosπŸ‘‘β€’9mo ago
yeah, but don't use ChatGPT
π’»π“‡π‘’π’Άπ“€π“Ž
ok i did not kown sorry Error pinging the nodes: Error [InteractionAlreadyReplied]: The reply to this interaction has already been sent or deferred. at ChatInputCommandInteraction.reply (/home/container/node_modules/discord.js/src/structures/interfaces/InteractionResponses.js:102:46) at Object.execute (/home/container/commands/server/nodepinger.js:36:27) at processTicksAndRejections (node:internal/process/task_queues:95:5) at async Object.execute (/home/container/events/interactionCreate.js:16:4) { code: 'InteractionAlreadyReplied' } Error [InteractionAlreadyReplied]: The reply to this interaction has already been sent or deferred. at ChatInputCommandInteraction.reply (/home/container/node_modules/discord.js/src/structures/interfaces/InteractionResponses.js:102:46) at Object.execute (/home/container/commands/server/nodepinger.js:42:25) at processTicksAndRejections (node:internal/process/task_queues:95:5) at async Object.execute (/home/container/events/interactionCreate.js:16:4) { code: 'InteractionAlreadyReplied' } @-CarlosπŸ‘‘
-CarlosπŸ‘‘
-CarlosπŸ‘‘β€’9mo ago
use editReply() instead of reply() on the interaction
π’»π“‡π‘’π’Άπ“€π“Ž
fixed it anothor problem with my other command embed Error retrieving node information: TypeError: (intermediate value).setTitle(...).setColor(...).addField is not a function at Object.execute (/home/container/commands/server/nodepinger.js:35:26) at processTicksAndRejections (node:internal/process/task_queues:95:5) at async Object.execute (/home/container/events/interactionCreate.js:16:4) const { SlashCommandBuilder } = require('@discordjs/builders'); const { EmbedBuilder } = require('discord.js'); const axios = require('axios'); module.exports = { data: new SlashCommandBuilder() .setName('node') .setDescription('Retrieve information about a specific node.') .addStringOption(option => option.setName('nodename') .setDescription('Name of the node') .setRequired(true)), async execute(interaction) { try { if (interaction.deferred) return; // Check if already deferred const nodeName = interaction.options.getString('nodename'); const response = await axios.get('https://panel.nauticalmc.net/api/application/nodes', { headers: { Authorization: 'Bearer ptla_ZkiEC7bmMS5a6IvrfWwGI3Ue3EW1SFlxXigiJ2nrl4Y', 'Content-Type': 'application/json' } }); if (response.status === 200) { const nodes = response.data.data; const node = nodes.find(node => node.attributes.name.toLowerCase().startsWith(nodeName.toLowerCase())); if (node) { const embed = new EmbedBuilder() .setTitle(${node.attributes.name} Information) .setColor('#57F287') .addField('Description', node.attributes.description || 'N/A') .addField('Location ID', node.attributes.location_id) .addField('FQDN', node.attributes.fqdn) .addField('Scheme', node.attributes.scheme) .addField('Memory', node.attributes.memory) .addField('Disk', node.attributes.disk) .addField('Maintenance Mode', node.attributes.maintenance_mode ? 'Enabled' : 'Disabled'); await interaction.reply({ embeds: [embed] }); } else { await interaction.reply(Node with name "${nodeName}" not found.); } } else { await interaction.reply('Failed to retrieve node information.'); } } catch (error) { console.error('Error retrieving node information:', error); await interaction.reply('Error retrieving node information.'); } }, };
-CarlosπŸ‘‘
-CarlosπŸ‘‘β€’9mo ago
it's .addFields() on v14
π’»π“‡π‘’π’Άπ“€π“Ž
ok Error retrieving node information: CombinedPropertyError (2) Received one or more errors input[0] | ValidationError > s.object(T) | Expected the value to be an object, but received string instead | | Received: | | 'Description' input[1] | ValidationError > s.object(T) | Expected the value to be an object, but received string instead | | Received: | | 'N/A' at _ArrayValidator.handle (/home/container/node_modules/@sapphire/shapeshift/dist/cjs/index.cjs:480:70) at _ArrayValidator.parse (/home/container/node_modules/@sapphire/shapeshift/dist/cjs/index.cjs:216:88) at EmbedBuilder.addFields (/home/container/node_modules/@discordjs/builders/src/messages/embed/Embed.ts:116:29) at Object.execute (/home/container/commands/server/nodepinger.js:35:26) at processTicksAndRejections (node:internal/process/task_queues:95:5) at async Object.execute (/home/container/events/interactionCreate.js:16:4
-CarlosπŸ‘‘
-CarlosπŸ‘‘β€’9mo ago
show your full code
π’»π“‡π‘’π’Άπ“€π“Ž
const { SlashCommandBuilder } = require('@discordjs/builders'); const { EmbedBuilder } = require('discord.js'); const axios = require('axios'); module.exports = { data: new SlashCommandBuilder() .setName('node') .setDescription('Retrieve information about a specific node.') .addStringOption(option => option.setName('nodename') .setDescription('Name of the node') .setRequired(true)), async execute(interaction) { try { if (interaction.deferred) return; // Check if already deferred const nodeName = interaction.options.getString('nodename'); const response = await axios.get('https://panel.nauticalmc.net/api/application/nodes', { headers: { Authorization: 'Bearer no api key', 'Content-Type': 'application/json' } }); if (response.status === 200) { const nodes = response.data.data; const node = nodes.find(node => node.attributes.name.toLowerCase().startsWith(nodeName.toLowerCase())); if (node) { const embed = new EmbedBuilder() .setTitle(${node.attributes.name} Information) .setColor('#57F287') .addFields('Description', node.attributes.description || 'N/A') .addFields('Location ID', node.attributes.location_id) .addFields('FQDN', node.attributes.fqdn) .addFields('Scheme', node.attributes.scheme) .addFields('Memory', node.attributes.memory) .addFields('Disk', node.attributes.disk) .addFields('Maintenance Mode', node.attributes.maintenance_mode ? 'Enabled' : 'Disabled'); await interaction.reply({ embeds: [embed] }); } else { await interaction.reply(Node with name "${nodeName}" not found.); } } else { await interaction.reply('Failed to retrieve node information.'); } } catch (error) { console.error('Error retrieving node information:', error); await interaction.reply('Error retrieving node information.'); } }, };
-CarlosπŸ‘‘
-CarlosπŸ‘‘β€’9mo ago
no..
d.js docs
d.js docsβ€’9mo ago
:method: EmbedBuilder#addFields() Appends fields to the embed
π’»π“‡π‘’π’Άπ“€π“Ž
so like this .addFields( { name: 'Field 1', value: 'Value 1' }, { name: 'Field 2', value: 'Value 2' }, );
-CarlosπŸ‘‘
-CarlosπŸ‘‘β€’9mo ago
yeah
π’»π“‡π‘’π’Άπ“€π“Ž
Error retrieving node information: CombinedPropertyError (3) Received one or more errors input[0] | CombinedPropertyError (1) | Received one or more errors | | input.value | | ValidationError > s.string | | Expected a string primitive | | | | Received: | | | 1 input[3] | CombinedPropertyError (1) | Received one or more errors | | input.value | | ValidationError > s.string | | Expected a string primitive | | | | Received: | | | 24576 input[4] | CombinedPropertyError (1) | Received one or more errors | | input.value | | ValidationError > s.string | | Expected a string primitive | | | | Received: | | | 1024000 at _ArrayValidator.handle (/home/container/node_modules/@sapphire/shapeshift/dist/cjs/index.cjs:480:70) at _ArrayValidator.parse (/home/container/node_modules/@sapphire/shapeshift/dist/cjs/index.cjs:216:88) at EmbedBuilder.addFields (/home/container/node_modules/@discordjs/builders/src/messages/embed/Embed.ts:116:29) at Object.execute (/home/container/commands/server/nodepinger.js:35:26) at processTicksAndRejections (node:internal/process/task_queues:95:5) at async Object.execute (/home/container/events/interactionCreate.js:16:4) const { SlashCommandBuilder } = require('@discordjs/builders'); const { EmbedBuilder } = require('discord.js'); const axios = require('axios'); module.exports = { data: new SlashCommandBuilder() .setName('node') .setDescription('Retrieve information about a specific node.') .addStringOption(option => option.setName('nodename') .setDescription('Name of the node') .setRequired(true)), async execute(interaction) { try { if (interaction.deferred) return; // Check if already deferred const nodeName = interaction.options.getString('nodename'); const response = await axios.get('https://panel.nauticalmc.net/api/application/nodes', { headers: { Authorization: 'Bearer ', 'Content-Type': 'application/json' } }); if (response.status === 200) { const nodes = response.data.data; const node = nodes.find(node => node.attributes.name.toLowerCase().startsWith(nodeName.toLowerCase())); if (node) { const embed = new EmbedBuilder() .setTitle(${node.attributes.name} Information) .setColor('#57F287') .addFields( { name: 'Location ID', value: node.attributes.location_id }, { name: 'FQDN', value: node.attributes.fqdn }, { name: 'Scheme', value: node.attributes.scheme }, { name: 'Memory', value: node.attributes.memory }, { name: 'Disk', value: node.attributes.disk }, { name: 'Maintenance Mode', value: node.attributes.maintenance_mode ? 'Enabled' : 'Disabled' } );
await interaction.reply({ embeds: [embed] }); } else { await interaction.reply(Node with name "${nodeName}" not found.); } } else { await interaction.reply('Failed to retrieve node information.'); } } catch (error) { console.error('Error retrieving node information:', error); await interaction.reply('Error retrieving node information.'); } }, }; @-CarlosπŸ‘‘
-CarlosπŸ‘‘
-CarlosπŸ‘‘β€’9mo ago
can you atleast put your code on a code block
d.js docs
d.js docsβ€’9mo ago
Codeblocks: ```js const Discord = require("discord.js"); // further code ``` becomes
const Discord = require("discord.js");
// further code
const Discord = require("discord.js");
// further code
Inline Code: `console.log('inline!');` becomes console.log('inline!');
π’»π“‡π‘’π’Άπ“€π“Ž
const { SlashCommandBuilder } = require('@discordjs/builders');
const { EmbedBuilder } = require('discord.js');
const axios = require('axios');

module.exports = {
data: new SlashCommandBuilder()
.setName('node')
.setDescription('Retrieve information about a specific node.')
.addStringOption(option =>
option.setName('nodename')
.setDescription('Name of the node')
.setRequired(true)),

async execute(interaction) {
try {
if (interaction.deferred) return; // Check if already deferred

const nodeName = interaction.options.getString('nodename');

const response = await axios.get('https://panel.nauticalmc.net/api/application/nodes', {
headers: {
Authorization: 'Bearer ',
'Content-Type': 'application/json'
}
});

if (response.status === 200) {
const nodes = response.data.data;
const node = nodes.find(node => node.attributes.name.toLowerCase().startsWith(nodeName.toLowerCase()));

if (node) {
const embed = new EmbedBuilder()
.setTitle(${node.attributes.name} Information)
.setColor('#57F287')
.addFields(
{ name: 'Location ID', value: node.attributes.location_id },
{ name: 'FQDN', value: node.attributes.fqdn },
{ name: 'Scheme', value: node.attributes.scheme },
{ name: 'Memory', value: node.attributes.memory },
{ name: 'Disk', value: node.attributes.disk },
{ name: 'Maintenance Mode', value: node.attributes.maintenance_mode ? 'Enabled' : 'Disabled' }
);

await interaction.reply({ embeds: [embed] });
} else {
await interaction.reply(Node with name "${nodeName}" not found.);
}
} else {
await interaction.reply('Failed to retrieve node information.');
}
} catch (error) {
console.error('Error retrieving node information:', error);
await interaction.reply('Error retrieving node information.');
}
},
};
const { SlashCommandBuilder } = require('@discordjs/builders');
const { EmbedBuilder } = require('discord.js');
const axios = require('axios');

module.exports = {
data: new SlashCommandBuilder()
.setName('node')
.setDescription('Retrieve information about a specific node.')
.addStringOption(option =>
option.setName('nodename')
.setDescription('Name of the node')
.setRequired(true)),

async execute(interaction) {
try {
if (interaction.deferred) return; // Check if already deferred

const nodeName = interaction.options.getString('nodename');

const response = await axios.get('https://panel.nauticalmc.net/api/application/nodes', {
headers: {
Authorization: 'Bearer ',
'Content-Type': 'application/json'
}
});

if (response.status === 200) {
const nodes = response.data.data;
const node = nodes.find(node => node.attributes.name.toLowerCase().startsWith(nodeName.toLowerCase()));

if (node) {
const embed = new EmbedBuilder()
.setTitle(${node.attributes.name} Information)
.setColor('#57F287')
.addFields(
{ name: 'Location ID', value: node.attributes.location_id },
{ name: 'FQDN', value: node.attributes.fqdn },
{ name: 'Scheme', value: node.attributes.scheme },
{ name: 'Memory', value: node.attributes.memory },
{ name: 'Disk', value: node.attributes.disk },
{ name: 'Maintenance Mode', value: node.attributes.maintenance_mode ? 'Enabled' : 'Disabled' }
);

await interaction.reply({ embeds: [embed] });
} else {
await interaction.reply(Node with name "${nodeName}" not found.);
}
} else {
await interaction.reply('Failed to retrieve node information.');
}
} catch (error) {
console.error('Error retrieving node information:', error);
await interaction.reply('Error retrieving node information.');
}
},
};
@-CarlosπŸ‘‘
-CarlosπŸ‘‘
-CarlosπŸ‘‘β€’9mo ago
embed fields values must be strings
π’»π“‡π‘’π’Άπ“€π“Ž
ok but how it node.thing.thing gonna change into a placeholder for the numner
-CarlosπŸ‘‘
-CarlosπŸ‘‘β€’9mo ago
by making them a string
-CarlosπŸ‘‘
-CarlosπŸ‘‘β€’9mo ago
either use .toString() or put them inside a ${} I would recommend using the second option
π’»π“‡π‘’π’Άπ“€π“Ž
do get rid of "" and replace with ${} or "${string}"
-CarlosπŸ‘‘
-CarlosπŸ‘‘β€’9mo ago
you aren't using " on your fields
π’»π“‡π‘’π’Άπ“€π“Ž
{ name: 'Location ID', value: "${node.attributes.location_id}" }, this
-CarlosπŸ‘‘
-CarlosπŸ‘‘β€’9mo ago
no, here's an example:
.addFields({ name: 'Location ID', value: `${node.attributes.location_id}` });
.addFields({ name: 'Location ID', value: `${node.attributes.location_id}` });
π’»π“‡π‘’π’Άπ“€π“Ž
ok .setTitle(${node.attributes.name} Information) .setColor('#57F287') .addFields( { name: 'Location ID', value: '${node.attributes.location_id}' }, { name: 'FQDN', value: '${node.attributes.fqdn}' }, { name: 'Scheme', value: '${node.attributes.scheme}' }, { name: 'Memory', value: '${node.attributes.memory}' }, { name: 'Disk', value: '${node.attributes.disk}' }, { name: 'Maintenance Mode', value: '${node.attributes.maintenance_mode}' ? 'Enabled' : 'Disabled' } ); `
-CarlosπŸ‘‘
-CarlosπŸ‘‘β€’9mo ago
it's ` instead of '
π’»π“‡π‘’π’Άπ“€π“Ž
ok can help me add autocomple
const { SlashCommandBuilder } = require('@discordjs/builders');
const { EmbedBuilder } = require('discord.js');
const axios = require('axios');

module.exports = {
data: new SlashCommandBuilder()
.setName('node')
.setDescription('Retrieve information about a specific node.')
.addStringOption(option =>
option.setName('nodename')
.setDescription('Name of the node')
.setRequired(true)),

async execute(interaction) {
try {
if (interaction.deferred) return; // Check if already deferred

const nodeName = interaction.options.getString('nodename');

const response = await axios.get('https://panel.nauticalmc.net/api/application/nodes', {
headers: {
Authorization: 'Bearer ',
'Content-Type': 'application/json'
}
});

if (response.status === 200) {
const nodes = response.data.data;
const node = nodes.find(node => node.attributes.name.toLowerCase().startsWith(nodeName.toLowerCase()));

if (node) {
const embed = new EmbedBuilder()
.setTitle(`${node.attributes.name} Information`)
.setColor('#57F287')
.addFields(
{ name: 'Location ID', value: `${node.attributes.location_id}` },
{ name: 'FQDN', value: `${node.attributes.fqdn}` },
{ name: 'Scheme', value: `${node.attributes.scheme}` },
{ name: 'Memory', value: `${node.attributes.memory}` },
{ name: 'Disk', value: `${node.attributes.disk}` },
{ name: 'Maintenance Mode', value: `${node.attributes.maintenance_mode}`}
);

await interaction.reply({ embeds: [embed] });
} else {
await interaction.reply(`Node with name "${nodeName}" not found.`);
}
} else {
await interaction.reply('Failed to retrieve node information.');
}
} catch (error) {
console.error('Error retrieving node information:', error);
await interaction.reply('Error retrieving node information.');
}
},
};
const { SlashCommandBuilder } = require('@discordjs/builders');
const { EmbedBuilder } = require('discord.js');
const axios = require('axios');

module.exports = {
data: new SlashCommandBuilder()
.setName('node')
.setDescription('Retrieve information about a specific node.')
.addStringOption(option =>
option.setName('nodename')
.setDescription('Name of the node')
.setRequired(true)),

async execute(interaction) {
try {
if (interaction.deferred) return; // Check if already deferred

const nodeName = interaction.options.getString('nodename');

const response = await axios.get('https://panel.nauticalmc.net/api/application/nodes', {
headers: {
Authorization: 'Bearer ',
'Content-Type': 'application/json'
}
});

if (response.status === 200) {
const nodes = response.data.data;
const node = nodes.find(node => node.attributes.name.toLowerCase().startsWith(nodeName.toLowerCase()));

if (node) {
const embed = new EmbedBuilder()
.setTitle(`${node.attributes.name} Information`)
.setColor('#57F287')
.addFields(
{ name: 'Location ID', value: `${node.attributes.location_id}` },
{ name: 'FQDN', value: `${node.attributes.fqdn}` },
{ name: 'Scheme', value: `${node.attributes.scheme}` },
{ name: 'Memory', value: `${node.attributes.memory}` },
{ name: 'Disk', value: `${node.attributes.disk}` },
{ name: 'Maintenance Mode', value: `${node.attributes.maintenance_mode}`}
);

await interaction.reply({ embeds: [embed] });
} else {
await interaction.reply(`Node with name "${nodeName}" not found.`);
}
} else {
await interaction.reply('Failed to retrieve node information.');
}
} catch (error) {
console.error('Error retrieving node information:', error);
await interaction.reply('Error retrieving node information.');
}
},
};
node names
-CarlosπŸ‘‘
-CarlosπŸ‘‘β€’9mo ago
wdym
π’»π“‡π‘’π’Άπ“€π“Ž
DE-1, "DE-2, "DE-3, GB-1 USA-1 for autocomple
-CarlosπŸ‘‘
-CarlosπŸ‘‘β€’9mo ago
i'm not really familiar with autocomplete, but you can check this out: https://discordjs.guide/slash-commands/autocomplete.html#autocomplete
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
Want results from more Discord servers?
Add your server