当我从另一个用户那里得到帮助时,我通过id尝试了一个fetchMessage()。我猜想出了点问题,因为当我输入我的报告命令的ID时,它返回[object Promise]
而不是ID对应的消息。这是一个代码位及其输出内容:
if (cmd === `${prefix}report`) {
let messageID = args[0];
if (isNaN(messageID)) {
message.author.send("Not an ID")
return;
}
let messagea = message.channel.fetchMessages(messageID);
let reportEmbed = new Discord.RichEmbed()
.setTitle("Reports")
.setColor("#F7E533")
.addField("Message", messagea)
.addField("Reported User", `@${messagea.author}`)
.addField("Reported By", `${message.author} with ID: ${message.author.id}`)
.addField("Time", message.createdAt)
let reportschannel = message.guild.channels.find(`name`, botconfig.reportsChannel);
if (!reportschannel) return message.channel.send("Couldn't find reports channel.");
message.delete().catch(O_o => {});
reportschannel.send(reportEmbed);
message.delete();
return;
}
答案 0 :(得分:1)
message.channel.fetchMessages(messageID)
会返回承诺而不是邮件,您还应使用fetchMessage
代替fetchMessages
。
你需要等待这个承诺"给你信息"然后做你需要的。
message.channel.fetchMessage(messageID).then(messagea => {
let reportEmbed = new Discord.RichEmbed()
.setTitle("Reports")
.setColor("#F7E533")
.addField("Message", messagea.content)
.addField("Reported User", `@${messagea.author}`)
.addField("Reported By", `${message.author} with ID: ${message.author.id}`)
.addField("Time", message.createdAt)
let reportschannel = message.guild.channels.find(`name`, botconfig.reportsChannel);
if (!reportschannel) return message.channel.send("Couldn't find reports channel.");
message.delete().catch(O_o => {});
reportschannel.send(reportEmbed);
message.delete();
return;
})
此外,我已将messagea
更改为messagea.content
,因此它实际显示了消息