#[SOLVED] Unable to source error…

13 messages · Page 1 of 1 (latest)

cloud vine
#

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.
      }
    };
  }
}

…But wait there's more…

unkempt daggerBOT
#

• 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.

cloud vine
#
// 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:
```js
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;
}
serene barn
#

You remove the this reference from interaction.reply by storing it in an array like that. Not to mention that calling reply without any parameters would get you an empty message error because

#

And you can’t catch rejections of async function calls in a try-catch if you don’t await them in there

cloud vine
#

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?

serene barn
cloud vine
#

Oh okay, so when MessagePayload refers to this in its create method, it's not able to access that interaction?

cloud vine
#

So it's working now except for that timer.

#

[SOLVED] Unable to source error…