#thread locked is the check

1 messages · Page 1 of 1 (latest)

worldly bear
#

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?

maiden dirge
#

So you're trying to lock it if a certain tag is applied?

worldly bear
#

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

maiden dirge
#

Because you're doing it every time the thread is updated instead of only when the changes you want to look for happen

worldly bear
#

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

maiden dirge
#

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

worldly bear
#

!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

maiden dirge
#

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

worldly bear
#

the bot is doing it

#

but there is wait

maiden dirge
#

Yeah so you won't get a threadUpdate event where both properties change

worldly bear
#

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?

maiden dirge
#

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

worldly bear
#

it locks it first, so just do

        if (!oldThread.locked && newThread.locked) {
            console.log(`${newThread} is locked`);
            return;
          }
#

just that statement?

maiden dirge
#

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

worldly bear
#

yes so when it becomes locked it would return, meaning the code below wouldnt run so it wouldn't keep sending messages,

maiden dirge
#

Think through what would happen if the name changes or it becomes archived

worldly bear
#

oh it would fire the event again 🤦

maiden dirge
#

Yeah. Better to check for the specific change and only continue if that is true instead of excluding specific types of changes

worldly bear
#

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

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

worldly bear
worldly bear
#

@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

maiden dirge
#

Because you're looping through and sending the message in every archived thread

worldly bear
#

ye, is it b/c of the forEach?

#

cuz i dont understand how its looping still

maiden dirge
#

That's literally what forEach does. Loop through and do it for everything

worldly bear
#

ok, so just remove the foreach?

maiden dirge
#

Yes

worldly bear
#

Ok but then how would i define thread?

maiden dirge
#
    async execute(oldThread, newThread, client) {
```You have it twice right here
worldly bear
#

ok shit ur right

maiden dirge
#

Either of those can be sent to and will do the same thing

worldly bear
#

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

maiden dirge
#

Why do you need to fetch archived threads at all?

#

Or any other thread than the one that changed?

worldly bear
#

I mean I don't I guess