#thread locked is the check
1 messages · Page 1 of 1 (latest)
hi
@maiden dirge sorry, im not sure why what im doing isnt working
if (thread.appliedTags.includes('1090040450175475873')) {
if (thread.Locked) {
}
if (thread.Archived) {
}
await thread.send('This thread has been marked as solved.\n The thread will be closed shortly.');
await wait(5000);
await thread.setLocked(true);
await wait(60000);
await thread.setArchived(true);
};
i got this, should i but the .locked and .archoved if statemnets above the applied tags?
So you're trying to lock it if a certain tag is applied?
yes and archive, but it will keep spamming messages cuz the thread has the message send so it will jsut redo the event over and over
Because you're doing it every time the thread is updated instead of only when the changes you want to look for happen
ye, but isnt that what im doing for the .appliedtags statement? checking if the active post has that tag and if it does to do everything below
No, that's checking that the thread has the applied tags, not that the applied tags are what changed
Change the name, tags will be there
Lock the thread, tags will still be there
Hint: You want to compare the properties of the old and new thread objects to see what is different
!oldThread.archived && newThread.archived?
if (!oldThread.locked && newThread.locked) {
return;
}
``` so like that?
module.exports = {
name: "threadUpdate",
once: false,
async execute(oldThread, newThread, client) {
const threadchl = client.channels.cache.get('1090040369112170546');
const activeThreads = await threadchl.threads.fetchActive();
activeThreads.threads.forEach(async (thread) => {
if (oldThread.archived && !newThread.archived) {
console.log(`${newThread} is archived`);
}
if (oldThread.locked && !newThread.locked) {
console.log(`${newThread} is unlocked`);
}
if (thread.appliedTags.includes('1090040450175475873')) {
await thread.send('This thread has been marked as solved.\n The thread will be closed shortly.');
await wait(5000);
await thread.setArchived(true);
await wait(60000);
await thread.setLocked(true);
};
});
}};
``` this is what i got
so far and it isnt working
oh wait compare
not and
fuck
This is fine. You're not returning in your paste below though so it would log but still post infinitely
Well I guess it depends on how you're locking/archiving it. Both won't happen at the same exact time if you have a human doing it
Yeah so you won't get a threadUpdate event where both properties change
ye
module.exports = {
name: "threadUpdate",
once: false,
async execute(oldThread, newThread, client) {
const threadchl = client.channels.cache.get('1090040369112170546');
const activeThreads = await threadchl.threads.fetchActive();
activeThreads.threads.forEach(async (thread) => {
if (!oldThread.locked && newThread.locked) {
console.log(`${newThread} is locked`);
return;
}
if (!oldThread.archived && newThread.archived) {
console.log(`${newThread} is archived`);
return;
}
if (thread.appliedTags.includes('1090040450175475873')) {
await thread.send('This thread has been marked as solved.\n The thread will be closed shortly.');
await wait(5000);
await thread.setLocked(true);
await wait(60000);
await thread.setArchived(true);
};
});
}};
``` cuz i have this, and it still doesnt work
oh wait cuz im checking if the oldThread isnt locked/archived
i wanna see if both are locked/archived?
I'd just have one check for whether archived or locked changed (pick one) to whichever status you want and have that be the "trigger" that starts this
it locks it first, so just do
if (!oldThread.locked && newThread.locked) {
console.log(`${newThread} is locked`);
return;
}
just that statement?
That would return when it becomes locked. If you want it to continue when it becomes locked instead then flip it, but otherwise something like that yeah
yes so when it becomes locked it would return, meaning the code below wouldnt run so it wouldn't keep sending messages,
Think through what would happen if the name changes or it becomes archived
oh it would fire the event again 🤦
Yeah. Better to check for the specific change and only continue if that is true instead of excluding specific types of changes
Oh so just check if the tag was applied for oldthread and new thread?
activeThreads.threads.forEach(async (thread) => {
if (!oldThread.appliedTags.includes('1090040450175475873') && newThread.appliedTags.includes('1090040450175475873')) {
console.log(`${newThread} is resolved`);
return;
}
})
``` so just like that
Thank you so much
const inactiveThreads = await threadchl.threads.fetchArchived();
inactiveThreads.threads.forEach(async (thread) => {
if (oldThread.archived && !newThread.archived) {
await thread.send('This thread has been opened again');
console.log(`${newThread} is has been reopened`);
}
})
``` so I had this. and it send that message to every single thread that was closed
@maiden dirge
Not sure what you're trying to do there, but oldThread and newThread are the specific thread that was updated so behavior will be the same for each thing you're looping through. If you fetch all of the threads in a channel you'll only have one thread which represents the current state
im trying ot have it send a message when a closed thread is reopened
@maiden dirge
I type in a closed thread, it opens b/c i typed imn it, it then sends a message to every single archived thread
Because you're looping through and sending the message in every archived thread
That's literally what forEach does. Loop through and do it for everything
ok, so just remove the foreach?
Yes
Ok but then how would i define thread?
async execute(oldThread, newThread, client) {
```You have it twice right here
ok shit ur right
Either of those can be sent to and will do the same thing
Ok
but then what would it look like
const inactiveThreads = await threadchl.threads.fetchArchived();
if (inactiveThreads.oldThread.archived && !inactiveThreads.newThread.archived) {
await thread.send('This thread has been opened again');
console.log(${newThread} is has been reopened);
}
that?
idk how i would do it without the foreach
Why do you need to fetch archived threads at all?
Or any other thread than the one that changed?
I mean I don't I guess