我有这段代码,但是它不起作用,它返回了一些函数,我该如何解决呢?
module.exports = (client, message, edit) => {
const embed = new Discord.RichEmbed
const { prefix } = require("./config.json")
if (message.content.toLowerCase().startsWith(prefix + 'edit')) {
let messageID = message.content.split(' ').slice(1, 2).join(' ');
let myMessage = message.content.split(' ').slice(2).join(' ');
if (!messageID) return;
if (!myMessage) return;
message.channel.fetchMessage(messageID)
.then(m => m.edit(embed)
.then(message.delete().catch(() => { return })))
.catch(e => console.error(e));
}
}
答案 0 :(得分:0)
.then(message.delete().catch(() => { return })))
那条线是您问题的根源。 Promise.then()
使用了回调函数,但是您没有为其提供回调函数。实际传递给它的是message.delete().catch(() => { return }))
返回的值,这是一个未完成的承诺。
这与您要完成的工作等效(有效):
message.channel.fetchMessage(messageID)
.then(m => m.edit(embed)) // will run after above (unless above was rejected)
.then(m => m.delete()) // will run after above (unless above was rejected)
.catch(console.error); // will catch errors from any of the 3 promises