![](/img/trans.png)
[英]Discord.js | I'm trying to check if a role has a specific permission for a mute role
[英]I'm trying to check the note but this error comes up. | mongoose and discord.js
我收到此錯誤,稱為UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot send an empty message
我在這里做錯了什么? 我無法修復此錯誤,我正在嘗試讓機器人檢查我的 DISCORD ID,然后將我的“注釋”發送到屏幕截圖中的位置。
這是我的 mongodb 指南針的屏幕截圖。
這就是我的 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.")
}
}
這不是一個錯誤,而是一個警告,告訴您您尚未處理 promise 被拒絕的可能性。 您必須將您的await
語句包裝在 try/catch 中,或者在 promise 本身中捕獲錯誤。
試着抓:
try {
await noteModel.find({"UserId" : { $in : [noted.UserId]}});
await message.channel.send(noted.Note);
} catch(e) {
// Handle errors
}
在等待語句中捕獲:
await message.channel.send(noted.Note).catch((e) => console.log(e));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.