Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

549
Views
How to get multiple message IDs in discord.js?

My bot sends 3 messages following eachother and I need to save their IDs, because I need to edit them later. If I do something like this:

message.channel.send(`${acc[player].output.slot1}`).then((m) => {
  acc[player].ids.msg1 = m.id
})
  
message.channel.send(`${acc[player].output.slot2}`).then((n) => {
  acc[player].ids.msg2 = n.id
})
    
message.channel.send(`${acc[player].output.slot3}`).then((o) => {
  acc[player].ids.msg3 = o.id
})

all three will have the 3rd one's ID. Slowing down the process or doing it step by step didn't help.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Not sure why all 3 entries would result in the same value, however maybe handling the promises differently could help. Try awaiting Promise.all() with an array of the send messages and map all the results to the id.

const { send } = message.channel;

try {
   (await Promise.all([
      send(`${acc[player].slot1}`),
      send(`${acc[player].slot2}`),
      send(`${acc[player].slot3}`)
   ])).forEach((msg, i) => {
      acc.player.ids[`msg${i + 1}`] = msg.id;
   });
} catch (err) {
   console.error(err);
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!