const channel = client.channels.cache.get(channelID);
if (channel) {
const membersList = await channel.members.fetch()
if (!membersList.has(newMember.id)) {
channel.send(`${newMember.user} adding you here :3`);
} else {
console.log('User already in the threadList!')
}
}
本质上,问题是:如果在不和谐应用程序中手动关闭线程,通道=未定义,如果打开线程,则代码可以工作。 关闭的线程是否有可能未存档或存储在其他地方(不在 client.channels.cache 中)? 如果关闭了我需要打开它,但关闭后通过id找不到它。
本质上,问题是:如果在discord应用程序中手动关闭线程,则通道=未定义,如果打开线程则代码有效。
您必须获取存档的线程
let channel;
await parentChannel.threads.fetchArchived().then(() => {
channel = client.channels.cache.get(channelID);
})
如果您尝试查找的线程是私有线程,请使用
[...].threads.fetchArchived({ type: 'private', fetchAll: true })[...]
来源: