#finding embeds in channel

69 messages · Page 1 of 1 (latest)

misty tigerBOT
#

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

spring turtle
#

How would I do that

digital shell
#

like days or hours

spring turtle
#

days

#

@digital shell

#

in a specific channel

#

and then i'd like to filter for the content of the description

digital shell
agile jolt
#

since you can only fetch 100 messages at a time this is very impractical

digital shell
agile jolt
#

?

digital shell
#

like if we map 100 messsage then push and map 100 more again and again.

agile jolt
#

this is very impractical

#

and spams the api with requests

digital shell
#

What I would do :
on messagecreate,
If someone send a message that has an embed, you can push an object in a JSON with the channel id, message id, user id and the date(with a format)

#

On messageDelete
you can do a find on that json to delete that entry if found.So you keep that little database updated.

spring turtle
#

Well I want it to fetch about 50ish messages in a channel that have already been sent

digital shell
#

On a slash command create two field for the start and end date.

Then do a for on your JSON to find each message that still exist so you delete the one that are not.

Should look like that.

arrayMessageFound = []
arrayMessageNotFound = []
for (let message of arrayJSON){
let channelFind = guild.cache.channel.find(c => c.id === channel id )
if(channelFind){
let messageFound = channelFind.fetch(message id)
if(messageFound){
if( between those two dates) {
arrayMessagesFound.push(message)
}
} else {
arrayMessageNotFound.push(message)
}else {
arrayMessageNotFound.push(message)
}
}

Compare JSON and arrayMessageNotFound to remove them from the JSON

You can do what you want with that you got in the found array
[arrayMessagesFound]

misty tigerBOT
digital shell
#

This aint perfect since i'm on my phone in the wood

spring turtle
#

yeah and then filter out for the description of the embeds

agile jolt
#

resolve the promise from .fetch() and then just filter out non embeds with .filter()

digital shell
#

you can also add the description yeah

spring turtle
digital shell
#

With my method you would be limited

agile jolt
#

it returns a collection of messages

spring turtle
#

so I can use .filter?

agile jolt
#

yes, otherwise I wouldnt suggest it

spring turtle
#
    let channel = message.guild.channels.cache.get('781593437098475570')
    await channel.messages.fetch({ limit: 20 })
      .then(fetchedMsgs => {
        fetchedMsgs.filter(embed => embed.embeds.length > 0)
    }
#

something like that?

digital shell
#

this method will return that last 20 message messages

spring turtle
#

yeah which is good enough for my purpose

digital shell
#

not the last 20 with an embed

spring turtle
#

hmm

#

so what do you suggest?

digital shell
#

I mean yeah it will

#

like what I propose about

#

above

spring turtle
#

actually even if it doesn't, shouldn't make a difference

#

as the channel that im fetching messages from is a logigng channel with just embeds :)

digital shell
#

if you have 100 message inbetween of two embed

#

then you will capture 1 embed

#

So you have to find a methode to reduce the amound of request you make againt the API

#

and the rate

spring turtle
#

as i mentioned, the amount of embeds i need is limited anyways. shouldn't be an issue.

#

i'd just like to more importantly filter for the description of the embed

digital shell
#

on messageUpdate you can also update the JSON message description

digital shell
#

but what you want to have is just a count all the log that has a embed?

digital shell
spring turtle
#

but not just embeds, more specifically the description of the embed

spring turtle
digital shell
#

If you want to have access to it at any time you must save it somewhere

#

outside discord

#

At that point you must do thing on messageCreate, messageDelete, messageUpdate and a mix of find and delete to keep your file updated.

#

But you will have have to segment it so you don't pass the 50 requests second or 1000 10 minutes

mystic apex
# spring turtle yes and after a specific date

Just add the description filtering into your filter as a second condition chained with &&
@digital shell while you mean good your solution doesn’t fit their use-case and is overkill in this case

digital shell
spring turtle
#

this isn't working for some reason

mystic apex
mystic apex
#

What for? A find would return only one result, what would you map and filter then?

agile jolt
#

the code they are using is perfectly fine besides the filter itself