applied Tags

so im trying to make my bot send a message when a certain tag is applied to a thread
client.on(Events.ThreadUpdate, async (oldThread, newThread, channel) => {
console.log(newThread.appliedTags)

if (newThread.appliedTags === '1107649018902884393') channel.send({ content: 'working', ephemeral: true})

})
client.on(Events.ThreadUpdate, async (oldThread, newThread, channel) => {
console.log(newThread.appliedTags)

if (newThread.appliedTags === '1107649018902884393') channel.send({ content: 'working', ephemeral: true})

})
the tags get logged but nothing gets sent to the channel
32 Replies
d.js toolkit
d.js toolkit•3y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
eX
eX•3y ago
are you trying to send the message inside that thread? or sending the message to another channel?
keekztah
keekztahOP•3y ago
that thread
eX
eX•3y ago
also, appliedTags is an array[] so if there can only be one tag, itll always be appliedTags[0], if there can be multiple tags on the thread, youll need to loop thru the tags to see if the tag youre looking for exists
keekztah
keekztahOP•3y ago
if (newThread.appliedTags === ['1107649018902884393'])?
eX
eX•3y ago
or if (newThread.appliedTags[0] === '1107649018902884393') newThread.send({}) is usually better in my book as well, but not sure itd make any difference
keekztah
keekztahOP•3y ago
oh
eX
eX•3y ago
but yes, comparing the entire value of the array would work as well, so long as they cant select more than one tag
keekztah
keekztahOP•3y ago
ok thank you
eX
eX•3y ago
also, i dont think you can send a willy nilly ephemeral message... only in response to an interaction
keekztah
keekztahOP•3y ago
yea i just realized haha but, the message 'working' still sends even if its not the right tag im applying to the channel for instance, i want it to send when the tag "Beginner" appears, but the message still sends when the tag "Intermediate" appears
eX
eX•3y ago
try returning the .send() function
if (newThread.appliedTags[0] === '1107649018902884393') return newThread.send({ content: 'working', ephemeral: true});
if (newThread.appliedTags[0] === '1107649018902884393') return newThread.send({ content: 'working', ephemeral: true});
or
if (newThread.appliedTags[0] === '1107649018902884393') {
channel.send({ content: 'working', ephemeral: true});
}
if (newThread.appliedTags[0] === '1107649018902884393') {
channel.send({ content: 'working', ephemeral: true});
}
keekztah
keekztahOP•3y ago
that works only if the only tag is beginner
eX
eX•3y ago
im sorry what
keekztah
keekztahOP•3y ago
is there a way to make it so that if beginner is added, regardless of what other tags are applied, sends the message? sorry, it worked. but only if there is only one tag (beginner)
eX
eX•3y ago
correct, thats what i was saying before. if theres more than 1 tag, youll need to loop through the array of appliedTags
keekztah
keekztahOP•3y ago
ohhh ok thank you
eX
eX•3y ago
if (newThread.appliedTags.includes('This Tag')) {
// Do this any time This Tag exists
}
if (newThread.appliedTags.includes('This Tag')) {
// Do this any time This Tag exists
}
or something alongthose lines
keekztah
keekztahOP•3y ago
do i have to add the [0]
eX
eX•3y ago
no, the [0] just means look at the first array value only. if you console.log(newThread.appliedTags), you should see ['132456789', '987654321'] if there were 2 tags applied. when you run
if (newThread.appliedTags.includes('123456789')) {
// Do this any time This Tag exists
}
if (newThread.appliedTags.includes('123456789')) {
// Do this any time This Tag exists
}
it will look at each value in newThread.appliedTags (123456789 and 987654321), and if any of them match 123456789, itll execute the code also, beware that the message will likely send every time the thread is updated, because the appliedTags will be the same, since this is within the threadUpdate event. (so if the thread is renamed, etc itll resend) that can be avoided by comparing the oldThread.appliedTags to the newThread.appliedTags
keekztah
keekztahOP•3y ago
can u send an example im so sorry
eX
eX•3y ago
if (oldThread.appliedTags !== newThread.appliedTags && newThread.appliedTags.includes('This Tag')) {
// if the appliedTags on the "old version" of this thread are not the same as the appliedTags on the "new version" of this thread, AND the newThread has the appliedTag "This Tag", run this code
}
if (oldThread.appliedTags !== newThread.appliedTags && newThread.appliedTags.includes('This Tag')) {
// if the appliedTags on the "old version" of this thread are not the same as the appliedTags on the "new version" of this thread, AND the newThread has the appliedTag "This Tag", run this code
}
simply comparing the two "versions" of the thread
keekztah
keekztahOP•3y ago
so the 'this tag' would be the tag i want when sending the message right?
eX
eX•3y ago
yep
keekztah
keekztahOP•3y ago
for ex, beginner
eX
eX•3y ago
@ me if you need anything else, gonna be tabbed out into a different window
keekztah
keekztahOP•3y ago
perfect, thank you @ex_1 this is a whole different thing but youre very helpful so i wanted to see if you knew the answer i wanted to create a reminder for someone who ran a command x minutes ago- is this possible?
eX
eX•3y ago
using a 3rd party library, like cron, yes. or (a less good idea) using a timeout fuction to execute something after some time
keekztah
keekztahOP•3y ago
npmjs.com/package/cron this?
keekztah
keekztahOP•3y ago
is that against tos at all lol
eX
eX•3y ago
depends how you use it. if you use cron to send the same message every 10 seconds, technically yes thats api abuse. but if you send a message every hour, or every day, or one time 5 minutes after a particular event, it wouldnt be api abuse but thatd be a good question for someone else
keekztah
keekztahOP•3y ago
do you use cron urself?

Did you find this page helpful?