#Question about `.then()`

9 messages · Page 1 of 1 (latest)

tepid grail

Here are two examples, which one would work?js let targetChannel = null; if (systemChannel) { targetChannel = systemChannel; } else if (tempSysCh) { targetChannel = tempSysCh; } else { const dm = await owner .send(`Please Wait... ${e.loading}`) .then((targetChannel = owner), dm.edit("")) .catch(() => null); }orjs //on this one the dm is underlined let targetChannel = null; if (systemChannel) { targetChannel = systemChannel; } else if (tempSysCh) { targetChannel = tempSysCh; } else { const dm = await owner .send(`Please Wait... ${e.loading}`) .then((dm) => { targetChannel = owner; dm.edit(""); }) .catch(() => null); }

narrow cloudBOT
  • 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!
tepid grail

Option 1:

Option 2:

tepid grail

Option 3:

Would Option 3 work?

buoyant patio

Option 2 would be correct but you don’t use the const dm which you define so don’t need it. Option 3 would also be correct but you don’t edit the dm message there. So it does something else than option 2. option 1 is simply wrong syntax because then(..) expects a function as first parameter

tepid grail
visual pelican

Also , for good practices , you don’t need to initialize targetchannel as null , doing this would be the same thing
let targetChannel;