interaction is not defined

const { EmbedBuilder } = require('discord.js');


function errorMessage(message) {
const reply = new EmbedBuilder()
.setColor('Red')
.setDescription(message);
return interaction.reply({embeds: [reply]});
}

module.exports = errorMessage
const { EmbedBuilder } = require('discord.js');


function errorMessage(message) {
const reply = new EmbedBuilder()
.setColor('Red')
.setDescription(message);
return interaction.reply({embeds: [reply]});
}

module.exports = errorMessage
I know this sound weird/retarded but hear me out, So I am creating a message.js (kinda) for my bot where I can use this function to reply with an embed without having to define it from every single file with something like this
errorMessage('I have an error')
errorMessage('I have an error')
9 Replies
d.js toolkit
d.js toolkit•12mo 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 OP
-Carlos🎃
-Carlos🎃•12mo ago
interaction is not defined
Nightro-Fx
Nightro-Fx•12mo ago
I know but how do I define it...
-Carlos🎃
-Carlos🎃•12mo ago
by defining it? pass it with the function
Nightro-Fx
Nightro-Fx•12mo ago
function errorMessage(interaction, message) {
const reply = new EmbedBuilder()
.setColor('Red')
.setDescription(message);
return interaction.reply({embeds: [reply]});
}
function errorMessage(interaction, message) {
const reply = new EmbedBuilder()
.setColor('Red')
.setDescription(message);
return interaction.reply({embeds: [reply]});
}
Like this?
-Carlos🎃
-Carlos🎃•12mo ago
sure
Nightro-Fx
Nightro-Fx•12mo ago
@-Carlos👑 OH it worked Tysm
-Carlos🎃
-Carlos🎃•12mo ago
np
Nightro-Fx
Nightro-Fx•12mo ago
Solution: - In message.js
const { EmbedBuilder } = require('discord.js');


function errorMessage(interaction, message) {
const reply = new EmbedBuilder()
.setColor('Red')
.setDescription(message);
return interaction.reply({embeds: [reply]});
}

module.exports = errorMessage
const { EmbedBuilder } = require('discord.js');


function errorMessage(interaction, message) {
const reply = new EmbedBuilder()
.setColor('Red')
.setDescription(message);
return interaction.reply({embeds: [reply]});
}

module.exports = errorMessage
- In your desired file
let errorMessage = require('./path-to-your-function-file')
errorMessage(interaction,"I have an Error!")
let errorMessage = require('./path-to-your-function-file')
errorMessage(interaction,"I have an Error!")
Want results from more Discord servers?
Add your server