#applied Tags

43 messages · Page 1 of 1 (latest)

thick cave
#

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})
  
})```

the tags get logged but nothing gets sent to the channel
weak minnowBOT
#

• 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.

peak escarp
#

are you trying to send the message inside that thread? or sending the message to another channel?

thick cave
#

that thread

peak escarp
#

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

thick cave
#

if (newThread.appliedTags === ['1107649018902884393'])?

peak escarp
#

or if (newThread.appliedTags[0] === '1107649018902884393')

newThread.send({}) is usually better in my book as well, but not sure itd make any difference

thick cave
#

oh

peak escarp
#

but yes, comparing the entire value of the array would work as well, so long as they cant select more than one tag

thick cave
#

ok thank you

peak escarp
#

also, i dont think you can send a willy nilly ephemeral message... only in response to an interaction

thick cave
#

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

peak escarp
#

try returning the .send() function

if (newThread.appliedTags[0] === '1107649018902884393') return newThread.send({ content: 'working', ephemeral: true});

or

if (newThread.appliedTags[0] === '1107649018902884393') {
   channel.send({ content: 'working', ephemeral: true});
}
thick cave
#

that works only if the only tag is beginner

peak escarp
#

im sorry what

thick cave
#

is there a way to make it so that if beginner is added, regardless of what other tags are applied, sends the message?

thick cave
peak escarp
#

correct, thats what i was saying before. if theres more than 1 tag, youll need to loop through the array of appliedTags

thick cave
#

ohhh ok thank you

peak escarp
#
if (newThread.appliedTags.includes('This Tag')) {
   // Do this any time This Tag exists
}

or something alongthose lines

thick cave
#

do i have to add the [0]

peak escarp
#

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 ```js
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

thick cave
#

send an example im so sorry

peak escarp
#
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

thick cave
#

so the 'this tag' would be the tag i want when sending the message right?

peak escarp
#

yep

thick cave
#

for ex, beginner

peak escarp
#

@ me if you need anything else, gonna be tabbed out into a different window

thick cave
#

perfect, thank you

thick cave
#

@peak escarp 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?

peak escarp
thick cave
peak escarp
#

yes
https://www.npmjs.com/package/cron

setTimeout(function() {
  // do something after 1000 milliseconds
}, 1000);
thick cave
#

is that against tos at all lol

peak escarp
#

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