[SOLVED] Unable to source error…

The code class AutodeleteReply:
class AutodeleteReply {
constructor(
interaction,
client,
expirationSeconds = 2,
baseMessageContent = "",
ephemeral = false,
embeds = []
) {
// Force expirationSeconds to be at least 1
expirationSeconds = Math.floor(Math.abs(expirationSeconds));
expirationSeconds = expirationSeconds < 1 ? 1 : expirationSeconds;

// Make sure all embeds are valid.
embeds.filter((embed) => embed instanceof Embed);

// Create time reference object.
const timeDeletionString = `${bold(
`This message will auto-delete`
)} in ${unixTimeTag(
getUnixTime(
getDateFromOffsets(new Date(), 0, expirationSeconds, 0, 0, 0, 0, 0, 0)
),
true
)}…`;

// Expand message.
const fullMessage =
baseMessageContent.length === 0
? timeDeletionString
: [baseMessageContent, timeDeletionString].join("\n\n");

let msgObj = {
content: fullMessage,
ephemeral: ephemeral,
};
if (embeds.length > 0) {
msgObj.embeds = embeds;
}

const actions = [interaction.reply, timer, interaction.deleteReply];
const payloads = [messageResolvable, expirationSeconds * 1000, null];

this.post = async function () {
if (actions.every((action) => typeof action === "function")) {
for (let actionIndex = 0; actionIndex < 3; actionIndex++) {
if (nudf(payloads[actionIndex])) {
await actions[actionIndex]();
} else {
await actions[actionIndex](payloads[actionIndex]);
}
}
} else {
// Custom error that yells at you if not everything in the 'actions' variable is a function.
}
};
}
}
class AutodeleteReply {
constructor(
interaction,
client,
expirationSeconds = 2,
baseMessageContent = "",
ephemeral = false,
embeds = []
) {
// Force expirationSeconds to be at least 1
expirationSeconds = Math.floor(Math.abs(expirationSeconds));
expirationSeconds = expirationSeconds < 1 ? 1 : expirationSeconds;

// Make sure all embeds are valid.
embeds.filter((embed) => embed instanceof Embed);

// Create time reference object.
const timeDeletionString = `${bold(
`This message will auto-delete`
)} in ${unixTimeTag(
getUnixTime(
getDateFromOffsets(new Date(), 0, expirationSeconds, 0, 0, 0, 0, 0, 0)
),
true
)}…`;

// Expand message.
const fullMessage =
baseMessageContent.length === 0
? timeDeletionString
: [baseMessageContent, timeDeletionString].join("\n\n");

let msgObj = {
content: fullMessage,
ephemeral: ephemeral,
};
if (embeds.length > 0) {
msgObj.embeds = embeds;
}

const actions = [interaction.reply, timer, interaction.deleteReply];
const payloads = [messageResolvable, expirationSeconds * 1000, null];

this.post = async function () {
if (actions.every((action) => typeof action === "function")) {
for (let actionIndex = 0; actionIndex < 3; actionIndex++) {
if (nudf(payloads[actionIndex])) {
await actions[actionIndex]();
} else {
await actions[actionIndex](payloads[actionIndex]);
}
}
} else {
// Custom error that yells at you if not everything in the 'actions' variable is a function.
}
};
}
}
…But wait there's more…
2 Replies
d.js toolkit
d.js toolkit2y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
Tuevon
TuevonOP2y ago
[email protected] v18.15.0
// class 'AutodeleteReply' is invoked in function 'replyAutoDelete':
const {
AutodeleteReply,
} = require("../embed_templates/communications/comms_embeds");

async function replyAutodelete(
interaction,
client,
messageContent = "",
expirationSeconds = 2,
ephemeral = false,
embeds = Array(0),
) {
const reply = new AutodeleteReply(
interaction,
client,
expirationSeconds,
messageContent,
ephemeral,
embeds,
);

reply.post();
}

module.exports = { replyAutodelete };
// class 'AutodeleteReply' is invoked in function 'replyAutoDelete':
const {
AutodeleteReply,
} = require("../embed_templates/communications/comms_embeds");

async function replyAutodelete(
interaction,
client,
messageContent = "",
expirationSeconds = 2,
ephemeral = false,
embeds = Array(0),
) {
const reply = new AutodeleteReply(
interaction,
client,
expirationSeconds,
messageContent,
ephemeral,
embeds,
);

reply.post();
}

module.exports = { replyAutodelete };
And itself is invoked elsewhere like so:
try {
replyAutodelete(
interaction,
client,
"Thank you for testing this feature.",
3,
true,
[]
);
} catch (replyAutodeleteProcessError) {
logErrorMessage(
interaction,
client,
"Reply-Autodelete",
roleMention("1109019453372518460"),
codeBlock(replyAutodeleteProcessError)
);
}
try {
replyAutodelete(
interaction,
client,
"Thank you for testing this feature.",
3,
true,
[]
);
} catch (replyAutodeleteProcessError) {
logErrorMessage(
interaction,
client,
"Reply-Autodelete",
roleMention("1109019453372518460"),
codeBlock(replyAutodeleteProcessError)
);
}
But the catch block is not being triggered here. Edit: The support function nudf:
function nudf(value) {
return value === null || value === undefined;
}
function nudf(value) {
return value === null || value === undefined;
}
Okay so just trying to understand the first part, are you saying that functions/methods only work with invoked and can't be stored? I was trying to call const timer = require("node:timers/promises").setTimeout; and it had no issues. Are arrays in particular the problem? Oh okay, so when MessagePayload refers to this in its create method, it's not able to access that interaction? Looks like I was overcomplicating things… by a lot So it's working now except for that timer. @qjuh Thank you for your help!
Want results from more Discord servers?
Add your server