我正在为不和谐的机器人。我正在尝试获取消息内容,该消息内容在创建后会自动发送到该频道。该消息包含一个“争吵ID”,并通过一条不同的命令自动生成,该命令创建频道,并在创建频道后将该重要信息发送到频道。我尝试获取的内容的消息将始终是该频道中发送的第一条消息。我最初是通过一个消息过滤器来工作的,该过滤器查看该机器人发送的第一条消息和最后一条消息,但是一旦该机器人发送了几条消息,它就不断提取错误的消息,所以我想到了这个……
if (message.channel.type == 'text') {
message.channel.fetchMessages({limit: 1}).then(messages => {
const botMessages = messages.filter(message => {
const startingMessage = message.content.includes("Player A");
}).catch(err => {
console.log('Error while fetching starting message!');
console.log(err);
console.log(startingMessage)
if (startingMessage.length > 1) {
const startingMessage = message.author.bot && startingMessage
} else {
message.channel.send("No brawl initiation message found!")
}
var brawlID = startingMessage.content.slice(-8) // slices off last 8 characters which is the brawlID I need (refer to screenshot linked above)
console.log(`Brawl ID is ${brawlID}`)
我要定位的消息是this。
的控制台出现错误(节点:20820)UnhandledPromiseRejectionWarning:TypeError: messages.filter(...)。catch不是函数
和
(节点:20820)UnhandledPromiseRejectionWarning:未处理的诺言 拒绝。该错误是由抛出异步内部引起的 没有捕获块或拒绝承诺 未使用.catch()处理。 (拒绝ID:1)
我知道我的.catch位置有问题,因为我有,但是它告诉我未正确处理。我无法通过ID来获取消息,因为不同的命令会自动创建频道并发送消息。
预先感谢您的帮助,或者通过其他方式仅提取发送到该频道的第一条消息(而不是通过消息ID找到它)。