'MessageEmbed' is declared but its value is never read.

I have no idea why this has happened, its my first encounter with this error.
No description
No description
47 Replies
d.js toolkit
d.js toolkit13mo 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! - Marked as resolved by staff
muffin.
muffin.OP13mo ago
async function checkEarthquakes() {
try {
const response = await axios.get('https://api.orhanaydogdu.com.tr/deprem/live.php?limit=1');
const earthquakeData = response.data.result[0];

if (earthquakeData) {
const embed = new Discord.MessageEmbed()
.setColor("0xff5733")
.setTitle('Earthquake in Turkey')
.addFields(
{ name: 'Magnitude', value: earthquakeData.mag, inline: true },
{ name: 'City', value: earthquakeData.city, inline: true },
{ name: 'District', value: earthquakeData.dist, inline: true }
)
.setTimestamp();

const guild = await client.guilds.fetch('1130895523088437249');
const channel = guild.channels.cache.get('1188055850800123975');

if (channel) {
channel.send({ embeds: [embed] });
} else {
console.error('Channel not found. Please check your channel ID.');
}
}
} catch (error) {
console.error('Error fetching earthquake data:', error);
}
}
async function checkEarthquakes() {
try {
const response = await axios.get('https://api.orhanaydogdu.com.tr/deprem/live.php?limit=1');
const earthquakeData = response.data.result[0];

if (earthquakeData) {
const embed = new Discord.MessageEmbed()
.setColor("0xff5733")
.setTitle('Earthquake in Turkey')
.addFields(
{ name: 'Magnitude', value: earthquakeData.mag, inline: true },
{ name: 'City', value: earthquakeData.city, inline: true },
{ name: 'District', value: earthquakeData.dist, inline: true }
)
.setTimestamp();

const guild = await client.guilds.fetch('1130895523088437249');
const channel = guild.channels.cache.get('1188055850800123975');

if (channel) {
channel.send({ embeds: [embed] });
} else {
console.error('Channel not found. Please check your channel ID.');
}
}
} catch (error) {
console.error('Error fetching earthquake data:', error);
}
}
const Discord = require("discord.js");
const { MessageEmbed } = require('discord.js');
const axios = require('axios');

const mySecret = process.env['token'];
const { Intents } = require("discord.js");
const Discord = require("discord.js");
const { MessageEmbed } = require('discord.js');
const axios = require('axios');

const mySecret = process.env['token'];
const { Intents } = require("discord.js");
Yes, this code is above the other one.
Error fetching earthquake data: RangeError [EMBED_FIELD_VALUE]: MessageEmbed field values must be non-empty strings.
at Util.verifyString (/home/runner/Chrimate-Observatory/node_modules/discord.js/src/util/Util.js:507:41)
at MessageEmbed.normalizeField (/home/runner/Chrimate-Observatory/node_modules/discord.js/src/structures/MessageEmbed.js:555:19)
at /home/runner/Chrimate-Observatory/node_modules/discord.js/src/structures/MessageEmbed.js:576:14
at Array.map (<anonymous>)
at MessageEmbed.normalizeFields (/home/runner/Chrimate-Observatory/node_modules/discord.js/src/structures/MessageEmbed.js:575:8)
at MessageEmbed.addFields (/home/runner/Chrimate-Observatory/node_modules/discord.js/src/structures/MessageEmbed.js:339:42)
at checkEarthquakes (/home/runner/Chrimate-Observatory/index.js:50:10)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
[Symbol(code)]: 'EMBED_FIELD_VALUE'
}
Error fetching earthquake data: RangeError [EMBED_FIELD_VALUE]: MessageEmbed field values must be non-empty strings.
at Util.verifyString (/home/runner/Chrimate-Observatory/node_modules/discord.js/src/util/Util.js:507:41)
at MessageEmbed.normalizeField (/home/runner/Chrimate-Observatory/node_modules/discord.js/src/structures/MessageEmbed.js:555:19)
at /home/runner/Chrimate-Observatory/node_modules/discord.js/src/structures/MessageEmbed.js:576:14
at Array.map (<anonymous>)
at MessageEmbed.normalizeFields (/home/runner/Chrimate-Observatory/node_modules/discord.js/src/structures/MessageEmbed.js:575:8)
at MessageEmbed.addFields (/home/runner/Chrimate-Observatory/node_modules/discord.js/src/structures/MessageEmbed.js:339:42)
at checkEarthquakes (/home/runner/Chrimate-Observatory/index.js:50:10)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
[Symbol(code)]: 'EMBED_FIELD_VALUE'
}
full stack error.
jay
jay13mo ago
im wondering why you have 3 imports to discord.js nevertheless this means your field values hasnt got any data
treble/luna
treble/luna13mo ago
also, the warning that you get is because you deconstruct MessageEmbed but you never call it You call Discord.MessageEmbed
muffin.
muffin.OP13mo ago
because of this
No description
treble/luna
treble/luna13mo ago
you indeed never use it
jay
jay13mo ago
instead you’re using Discord.MessageEmbed
muffin.
muffin.OP13mo ago
when I remove it its the same error though
treble/luna
treble/luna13mo ago
as you're told, why do you have 3 imports Either destructure or dont, but not both
muffin.
muffin.OP13mo ago
When I delete the imports it gives the same error
treble/luna
treble/luna13mo ago
. so pick what you want
muffin.
muffin.OP13mo ago
How do I desturcture it exactly
d.js docs
d.js docs13mo ago
mdn Destructuring assignment The destructuring assignment syntax is a JavaScript expression that makes it possible to unpack values from arrays, or properties from objects, into distinct variables.
treble/luna
treble/luna13mo ago
Pretty basic js
muffin.
muffin.OP13mo ago
Okay but why do I need to destructure if I just delete the imports and dont use them?
treble/luna
treble/luna13mo ago
its up to you what you want to do
muffin.
muffin.OP13mo ago
I did delete the imports
const Discord = require("discord.js");

const axios = require('axios');

const express = require("express");
const app = express();

app.listen(3000, () => {
console.log("Project is running!");
});

app.get("/", (req, res) => {
res.send("Hello world!");
});

const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES", "GUILD_MEMBERS"] });

// AUTO RATELIMIT-RESTART

client.on('debug', (ratelimit) => {
if (ratelimit.startsWith(`Hit a 429`)) {
process.kill(1);
}
});

client.on("rateLimit", data => {
require('child_process').exec('kill 1');
});

client.on('rateLimited', () => {
require('child_process').exec('kill 1');
});

// Check for earthquakes every 10 minutes (600,000 milliseconds)
setInterval(checkEarthquakes, 600000);
checkEarthquakes(); // Initial check when the bot starts

async function checkEarthquakes() {
try {
const response = await axios.get('https://api.orhanaydogdu.com.tr/deprem/live.php?limit=1');
const earthquakeData = response.data.result[0];

if (earthquakeData) {
const embed = new Discord.MessageEmbed()
.setColor("0xff5733")
.setTitle('Earthquake in Turkey')
.addFields(
{ name: 'Magnitude', value: earthquakeData.mag, inline: true },
{ name: 'City', value: earthquakeData.city, inline: true },
{ name: 'District', value: earthquakeData.dist, inline: true }
)
.setTimestamp();

const guild = await client.guilds.fetch('1130895523088437249');
const channel = guild.channels.cache.get('1188055850800123975');

if (channel) {
channel.send({ embeds: [embed] });
} else {
console.error('Channel not found. Please check your channel ID.');
}
}
} catch (error) {
console.error('Error fetching earthquake data:', error);
}
}

module.exports = client;
client.login(process.env.token);
const Discord = require("discord.js");

const axios = require('axios');

const express = require("express");
const app = express();

app.listen(3000, () => {
console.log("Project is running!");
});

app.get("/", (req, res) => {
res.send("Hello world!");
});

const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES", "GUILD_MEMBERS"] });

// AUTO RATELIMIT-RESTART

client.on('debug', (ratelimit) => {
if (ratelimit.startsWith(`Hit a 429`)) {
process.kill(1);
}
});

client.on("rateLimit", data => {
require('child_process').exec('kill 1');
});

client.on('rateLimited', () => {
require('child_process').exec('kill 1');
});

// Check for earthquakes every 10 minutes (600,000 milliseconds)
setInterval(checkEarthquakes, 600000);
checkEarthquakes(); // Initial check when the bot starts

async function checkEarthquakes() {
try {
const response = await axios.get('https://api.orhanaydogdu.com.tr/deprem/live.php?limit=1');
const earthquakeData = response.data.result[0];

if (earthquakeData) {
const embed = new Discord.MessageEmbed()
.setColor("0xff5733")
.setTitle('Earthquake in Turkey')
.addFields(
{ name: 'Magnitude', value: earthquakeData.mag, inline: true },
{ name: 'City', value: earthquakeData.city, inline: true },
{ name: 'District', value: earthquakeData.dist, inline: true }
)
.setTimestamp();

const guild = await client.guilds.fetch('1130895523088437249');
const channel = guild.channels.cache.get('1188055850800123975');

if (channel) {
channel.send({ embeds: [embed] });
} else {
console.error('Channel not found. Please check your channel ID.');
}
}
} catch (error) {
console.error('Error fetching earthquake data:', error);
}
}

module.exports = client;
client.login(process.env.token);
treble/luna
treble/luna13mo ago
killing your bot every time a ratelimit happens is a bad idea and wont magically solve it
muffin.
muffin.OP13mo ago
I have an uptimer which auto-restarts when its not working thats why
treble/luna
treble/luna13mo ago
well yeah but ratelimits wont crash your bot ratelimits can happen quite often but they don't cause your bot to crash so there's no need to kill it Nor will it solve it
muffin.
muffin.OP13mo ago
it does crash them
treble/luna
treble/luna13mo ago
Then catch your rejections properly
muffin.
muffin.OP13mo ago
it goes offline and never back online when I don't add them
treble/luna
treble/luna13mo ago
I highly doubt thats due to a ratelimit but ok i guess
muffin.
muffin.OP13mo ago
well still I dont understand whats the problem now the error says its about .addFields
treble/luna
treble/luna13mo ago
One of your field values is empty
muffin.
muffin.OP13mo ago
how so
treble/luna
treble/luna13mo ago
the error tells you
muffin.
muffin.OP13mo ago
.addFields(
{ name: 'Magnitude', value: earthquakeData.mag, inline: true },
{ name: 'City', value: earthquakeData.city, inline: true },
{ name: 'District', value: earthquakeData.dist, inline: true }
)
.addFields(
{ name: 'Magnitude', value: earthquakeData.mag, inline: true },
{ name: 'City', value: earthquakeData.city, inline: true },
{ name: 'District', value: earthquakeData.dist, inline: true }
)
treble/luna
treble/luna13mo ago
So log your values one of those is empty
muffin.
muffin.OP13mo ago
No description
muffin.
muffin.OP13mo ago
so the city and districts are empty
treble/luna
treble/luna13mo ago
or well, rather undefined
muffin.
muffin.OP13mo ago
yeah well thats a problem with the API I am using well I removed them completely and it still gives the same error even though the magnitude does have a value
treble/luna
treble/luna13mo ago
they also must be strings
muffin.
muffin.OP13mo ago
what do you mean? the values must be strings?
treble/luna
treble/luna13mo ago
yes
muffin.
muffin.OP13mo ago
so ${earthquakeData.mag} ?
treble/luna
treble/luna13mo ago
yes
muffin.
muffin.OP13mo ago
well that also didnt work
treble/luna
treble/luna13mo ago
didnt work in what way
muffin.
muffin.OP13mo ago
No description
treble/luna
treble/luna13mo ago
thats not a template literal
d.js docs
d.js docs13mo ago
mdn Template literals (Template strings) Template literals are literals delimited with backtick (`) characters, allowing for multi-line strings, string interpolation with embedded expressions, and special constructs called tagged templates.
muffin.
muffin.OP13mo ago
i feel kinda dumb for forgetting that well the code now works, thank you but uh the API is not working so thank you so much for you help
Martoz
Martoz13mo ago
what vscode theme?
muffin.
muffin.OP13mo ago
Its not VScode its replit The theme is "Coding Time"
Want results from more Discord servers?
Add your server