[英]Is there a way in Discord.js to unpin all pinned messages?
I am currently working on my first Discord bot and I wanted to unpin all pinned messages in a specific channel.我目前正在开发我的第一个 Discord 机器人,我想取消固定特定频道中的所有固定消息。 However, I have no idea how to get all the pinned messages.
但是,我不知道如何获取所有固定消息。
I tried to use message.channel.messages.fetchPinned().array()
to get an array of all pinned messages, but then I get an error that fetchPinned().array()
is not a function.我尝试使用
message.channel.messages.fetchPinned().array()
来获取所有固定消息的数组,但随后我收到一个错误,即fetchPinned().array()
不是 function。 What am I doing wrong?我究竟做错了什么?
fetchPinned
returns a promise, so you need to wait for it to be resolved first. fetchPinned
返回一个 promise,所以需要先等待解析。 Once it's resolved, it returns a collection of messages, so you can iterate over them using the each
method.一旦它被解析,它会返回一个消息集合,因此您可以使用
each
方法对它们进行迭代。
message.channel.messages
.fetchPinned()
.then((pinnedMessages) => {
pinnedMessages.each((msg) => msg.unpin().catch(console.error));
})
.catch(console.error);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.