2017-02-24 16 views
0

我一直在Discord.JS Bot上寫了很長時間,並且現在似乎在執行完成後會在控制檯中拋出一個隨機錯誤/警告其聊天命令之一 (特別是!clear)。DISCORD.JS>即使在處理完所有情況後,Promise仍然未解決

現在,我已經說過,我在我的控制檯得到的消息是警告,而不是實際的錯誤,所以這不是主要的問題,我有;

我的問題在於Discord方面的命令的執行:由於未解決,被拒絕的承諾,它根本不會執行!clear,所有消息都將包括命令本身留在後面。下面是我的代碼片段:

if (member.hasPermission("MANAGE_MESSAGES")) { 
    channel.fetchMessages({ limit: 100 }) 
     .then(messages => { 
      console.log(`Deleting ${messages.size} messages...`); 
      channel.bulkDelete(messages).then(res => {}, err => {}); 
      channel.sendEmbed({ 
       // Success Message 
      }).then(msg => msg.delete(10000), err => console.log(err)); 
     }, err => { console.log(err) }) 
} else { 
    channel.sendEmbed({ 
     // Permission Message 
    }).then(msg => msg.delete(10000), err => { console.log(err) }); 
} 

正如你所看到的,我解決了成功和每一個承諾的故障狀態中,兩個,但我仍然會看到控制檯以下警告:

(node:14768) Error: Bad Request Sometimes also throws Not Found

-- Stack Trace that only includes internal Node.JS errors --

(node:14768) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

-- More Stack Trace not regarding any of my own code --

如果您需要提供其他代碼來回答問題,請隨時問我,我會這樣做。此外,我不能+代表答案,但我總是欣賞'時間:)

+0

除了直接的問題,因爲它代表'channel.sendEmbed({/ *成功消息* /})'是獨立的'channel.bulkDelete(消息)',因此成功的訊息不是成功的可靠指標。這很容易通過鏈接'channel.bulkDelete(messages).then(()=> channel.sendEmbed(...)。然後(...))'來解決。 –

回答

0

您不處理msg.delete(10000)拒絕。你應該處理這樣的:

channel.sendEmbed({ 
    // Success Message 
}).then(msg => msg.delete(10000)).catch(err => console.log(err)); 
+0

這工作出奇的好!謝謝^^ – Maxx2709

+0

@ Maxx2709我建議不要使用promise的第二個參數'.then(success,failure)',而只能使用'.then(成功).catch(失敗) – idbehold

相關問題