Importing embed and message variables from another file.

Hi, i am trying to make a button that never expire, so im using the method of doing and even handler inside client.on in index.js The issue is that the button edits an embed message from a command reply. When i try to export the embed variable from the command file and do embed.spliceFields(), i get this error :
undefined
undefined
node:events:497
throw er; // Unhandled 'error' event
^

TypeError: Cannot read properties of undefined (reading 'spliceFields')
at Client.<anonymous> (C:\Users\const\Documents\Discord\Bots\Silas Sombrelune\src\index.js:84:27)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Emitted 'error' event on Client instance at:
at emitUnhandledRejectionOrErr (node:events:402:10)
at process.processTicksAndRejections (node:internal/process/task_queues:84:21)

Node.js v21.5.0
undefined
undefined
node:events:497
throw er; // Unhandled 'error' event
^

TypeError: Cannot read properties of undefined (reading 'spliceFields')
at Client.<anonymous> (C:\Users\const\Documents\Discord\Bots\Silas Sombrelune\src\index.js:84:27)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Emitted 'error' event on Client instance at:
at emitUnhandledRejectionOrErr (node:events:402:10)
at process.processTicksAndRejections (node:internal/process/task_queues:84:21)

Node.js v21.5.0
This is how i imported the embed :
const { raidmessage, raidembed } = require('./commands/Community/raid.js')
// raidembed = embed
// raidmessage = raidembed message sent by command reply with embeds: [raidembed]
const { raidmessage, raidembed } = require('./commands/Community/raid.js')
// raidembed = embed
// raidmessage = raidembed message sent by command reply with embeds: [raidembed]
The two "undefined" at the start of the error message are from :
client.on('interactionCreate', async (interaction) => {
// [...]
console.log(raidembed)
console.log(raidmessage)
// [...]
}
client.on('interactionCreate', async (interaction) => {
// [...]
console.log(raidembed)
console.log(raidmessage)
// [...]
}
So i assume the error is from how I import my variables... Could you help me please ? Feel free to ping me. Tell me if you need to see some code, and what part you need.
11 Replies
d.js toolkit
d.js toolkit5mo 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!
treble/luna
treble/luna5mo ago
and how are those embeds defined
'NoXz
'NoXz5mo ago
const raidembed = new Discord.EmbedBuilder()
.setTitle(`RAID DU ${interaction.options.getString(`date`)} A ${interaction.options.getString(`heure`)}`)
.setDescription(`# ${interaction.options.getString(`raid_nom`)}\n### <:skull:1193157255407882340> ${interaction.options.getString(`raid_difficulte`)} (${interaction.options.getString(`boss_vaincus`)})`)
.addFields(
{ name: `${client.emotes.tank} Tanks :`, value: `> Aucun tank pour le moment.` },
{ name: `${client.emotes.heal} Soutiens :`, value: `> Aucun soutien pour le moment.` },
{ name: `${client.emotes.dps} Dégâts :`, value: `> Aucun dégât pour le moment.` },
{ name: `\u200B`, value: `\u200B` },
{ name: `${client.emotes.abs} Absents :`, value: `> Aucun absent pour le moment.` }
)
.setColor(client.color)
.setImage(`https://michapx7.be/wp-content/uploads/2022/12/World-of-Warcraft-Dragonflight-Caveau-des-Incarnations-Head.jpg`)
.setFooter({ iconURL: `https://wowchallenges.com/images/questionmark.png`, text: `Merci de d'indiquer votre présence ou de signaler votre absence, comme demandé dans la charte de la guilde.` })


const raidmessage = await interaction.reply({
embeds: [raidembed],
components: [row]
})
const raidembed = new Discord.EmbedBuilder()
.setTitle(`RAID DU ${interaction.options.getString(`date`)} A ${interaction.options.getString(`heure`)}`)
.setDescription(`# ${interaction.options.getString(`raid_nom`)}\n### <:skull:1193157255407882340> ${interaction.options.getString(`raid_difficulte`)} (${interaction.options.getString(`boss_vaincus`)})`)
.addFields(
{ name: `${client.emotes.tank} Tanks :`, value: `> Aucun tank pour le moment.` },
{ name: `${client.emotes.heal} Soutiens :`, value: `> Aucun soutien pour le moment.` },
{ name: `${client.emotes.dps} Dégâts :`, value: `> Aucun dégât pour le moment.` },
{ name: `\u200B`, value: `\u200B` },
{ name: `${client.emotes.abs} Absents :`, value: `> Aucun absent pour le moment.` }
)
.setColor(client.color)
.setImage(`https://michapx7.be/wp-content/uploads/2022/12/World-of-Warcraft-Dragonflight-Caveau-des-Incarnations-Head.jpg`)
.setFooter({ iconURL: `https://wowchallenges.com/images/questionmark.png`, text: `Merci de d'indiquer votre présence ou de signaler votre absence, comme demandé dans la charte de la guilde.` })


const raidmessage = await interaction.reply({
embeds: [raidembed],
components: [row]
})
treble/luna
treble/luna5mo ago
and where do you export them also if you're just listening for buttons, use <ButtonInteraction>.message no need to export, you can access the embeds there
'NoXz
'NoXz5mo ago
in index.js from ./commands/Community/raid.js
treble/luna
treble/luna5mo ago
Thats importing importing and exporting is basic js And you dont even need it here since you can access the message from the ButtonInteraction
'NoXz
'NoXz5mo ago
so i could do : before:
raidembed.spliceFields(...)
await raidmessage.edit(...)
raidembed.spliceFields(...)
await raidmessage.edit(...)
after:
interaction.message.embeds.spliceFields(...)
await interaction.message.edit(...)
interaction.message.embeds.spliceFields(...)
await interaction.message.edit(...)
right ? if i understood well what you said
treble/luna
treble/luna5mo ago
embeds returns an array and you can just ise <Interaction>.update to edit the message
'NoXz
'NoXz5mo ago
okay thanks 👍 How do i get the fields in the embed ?
[
Embed {
data: {
type: 'rich',
title: 'RAID DU : A :',
image: [Object],
footer: [Object],
fields: [Array],
description: '# Caveau des Incarnations\n### <:skull:1193157255407882340> Normal (:)',
color: 9124820
}
}
]
[
Embed {
data: {
type: 'rich',
title: 'RAID DU : A :',
image: [Object],
footer: [Object],
fields: [Array],
description: '# Caveau des Incarnations\n### <:skull:1193157255407882340> Normal (:)',
color: 9124820
}
}
]
ik this is basic js but i forgot how to do it (i tried embed.fields but it returns undefined). or is it embed.data.fields ?
treble/luna
treble/luna5mo ago
embeds returns an array You should know how to get items from the array If not, i recommend brushing up on your js knowledge, #rules 3 #resources
'NoXz
'NoXz5mo ago
👍