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
33 Replies
d.js toolkit
d.js toolkit12mo 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
eX12mo ago
are you trying to send the message inside that thread? or sending the message to another channel?
keekztah
keekztah12mo ago
that thread
eX
eX12mo 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
keekztah12mo ago
if (newThread.appliedTags === ['1107649018902884393'])?
eX
eX12mo 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
keekztah12mo ago
oh
eX
eX12mo 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
keekztah12mo ago
ok thank you
eX
eX12mo ago
also, i dont think you can send a willy nilly ephemeral message... only in response to an interaction
keekztah
keekztah12mo 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
eX12mo 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
keekztah12mo ago
that works only if the only tag is beginner
eX
eX12mo ago
im sorry what
keekztah
keekztah12mo 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
eX12mo ago
correct, thats what i was saying before. if theres more than 1 tag, youll need to loop through the array of appliedTags
keekztah
keekztah12mo ago
ohhh ok thank you
eX
eX12mo 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
keekztah12mo ago
do i have to add the [0]
eX
eX12mo 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
keekztah12mo ago
can u send an example im so sorry
eX
eX12mo 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
keekztah12mo ago
so the 'this tag' would be the tag i want when sending the message right?
eX
eX12mo ago
yep
keekztah
keekztah12mo ago
for ex, beginner
eX
eX12mo ago
@ me if you need anything else, gonna be tabbed out into a different window
keekztah
keekztah12mo 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
eX12mo 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
keekztah12mo ago
npmjs.com/package/cron this?
eX
eX12mo ago
yes https://www.npmjs.com/package/cron
setTimeout(function() {
// do something after 1000 milliseconds
}, 1000);
setTimeout(function() {
// do something after 1000 milliseconds
}, 1000);
npm
cron
Cron jobs for your node. Latest version: 2.3.1, last published: a month ago. Start using cron in your project by running npm i cron. There are 1802 other projects in the npm registry using cron.
keekztah
keekztah12mo ago
is that against tos at all lol
eX
eX12mo 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
keekztah12mo ago
do you use cron urself?