Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

So this is my code for sending an embed, that says Loading shop with the dots changing. However, I am getting a pretty strange error message, which first tells me the error is at msg.delete() with "UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'delete' of undefined" and then a second one at the second msg.edit() saying "Cannot read property 'edit' of undefined". I searched up the docs and many forums, but the .then() syntax should be right. Any idea?

var embed = new Discord.MessageEmbed().setColor("GOLD").setTitle("Loading shop");
    msg.channel.send(embed)
        .then(msg => {setTimeout(()=>{msg.edit(embed.setTitle("Loading shop."))}, 500)})
        .then(msg => {setTimeout(()=>{msg.edit(embed.setTitle("Loading shop.."))}, 500)})
        .then(msg => {setTimeout(()=>{msg.edit(embed.setTitle("Loading shop..."))}, 500)})
        .then(msg => {setTimeout(()=>{msg.edit(embed.setTitle("Loading shop"))}, 500)})
        .then(msg => {setTimeout(()=>{msg.edit(embed.setTitle("Loading shop."))}, 500)})
        .then(msg => {setTimeout(()=>{msg.edit(embed.setTitle("Loading shop.."))}, 500)})
        .then(msg => {setTimeout(()=>{msg.edit(embed.setTitle("Loading shop..."))}, 500)})
        .then(msg => {msg.delete()});
question from:https://stackoverflow.com/questions/65923286/discord-js-msg-channel-send-then-promise-not-working

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
809 views
Welcome To Ask or Share your Answers For Others

1 Answer

  1. Do not use this all "thens"
  2. Use await

const embed = new Discord.MessageEmbed().setColor("GOLD").setTitle("Loading shop");
  const msg = message.channel.send(embed); // i change to message because msg will be used as var name
        setTimeout(() => {
      // do stuff
      msg.edit(embed.setTitle("Loading shop.")); // etc..
}, 500);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...