1

I'm getting this error called UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot send an empty message

What did I do wrong here? I can't fix this error, I'm trying to make the bot that checks my DISCORD ID and then sends my "Note" where thats in the screenshot.

Here is a screenshot from my mongodb compass.

https://i.stack.imgur.com/rM98a.jpg

This is what I have in my function.

async function checkNotes() {
  if(taggedUser !== undefined) {
    var d = new Date;

    function addZero(i) {
      if (i < 10) {
        i = "0" + i;
      }
      return i;
    }
    
    addZero(d.getMinutes());

      var d = new Date();
      var h = addZero(d.getHours());
      var m = addZero(d.getMinutes());

    dformat = [d.getFullYear(),
        d.getMonth()+1,
        d.getDate()].join('/');

    const noted = new noteModel ({
      _id: mdb.Types.ObjectId(),
      Note: args.slice(1).join(' '),
      User: taggedUser.username,
      UserId: taggedUser.id,
      getTime: dformat + " " + h + ":" + m
    });

  await noteModel.find({"UserId" : { $in : [noted.UserId]}});{
  await message.channel.send(noted.Note)
}
  }
else{
  message.channel.send("Nem választottál ki senkit.")
 }
}
BULLETBOT
  • 51
  • 11

1 Answers1

0

This is not an error, but rather a warning telling you that you have not handled the possibility of the promise being rejected. You'll have to either wrap your await statements in a try/catch, or catch errors in the promise itself.

Try/Catch:

try {
  await noteModel.find({"UserId" : { $in : [noted.UserId]}});
  await message.channel.send(noted.Note);
} catch(e) {
  // Handle errors
}

Catch in await statement:

await message.channel.send(noted.Note).catch((e) => console.log(e));
Marsroverr
  • 556
  • 1
  • 6
  • 23