#finding embeds in channel
69 messages · Page 1 of 1 (latest)
How would I do that
days
@digital shell
in a specific channel
and then i'd like to filter for the content of the description
I'm not sure sure about what the oldest message you can fetch in a channel.
since you can only fetch 100 messages at a time this is very impractical
arent we able to split the task
?
like if we map 100 messsage then push and map 100 more again and again.
I'm not saying this is good but there is way
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.
Well I want it to fetch about 50ish messages in a channel that have already been sent
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]
.
MessageManager#fetch()
Fetches message(s) from a channel. (more...)
This aint perfect since i'm on my phone in the wood
yeah and then filter out for the description of the embeds
resolve the promise from .fetch() and then just filter out non embeds with .filter()
you can also add the description yeah
i cant filter because it returns a json
With my method you would be limited
no, no it doesnt
it returns a collection of messages
so I can use .filter?
yes, otherwise I wouldnt suggest it
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?
this method will return that last 20 message messages
yeah which is good enough for my purpose
not the last 20 with an embed
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 :)
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
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
on messageUpdate you can also update the JSON message description
What i'm presenting is more like a complete usage
but what you want to have is just a count all the log that has a embed?
exactly
You need a date ?
but not just embeds, more specifically the description of the embed
yes and after a specific date
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
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
It is overkill yeah, but discord fetch only 100 messages
let channel = message.guild.channels.cache.get('781593437098475570')
await channel.messages.fetch({ limit: 20 })
.then(fetchedMsgs => {
console.log(fetchedMsgs)
let act = fetchedMsgs.filter(embed => embed.embeds.length > 0 && embed.author.name === 'ManuA12#8880')
this isn't working for some reason
And they only wanted 50 and now settled for 20
Because a User object has no name property
What for? A find would return only one result, what would you map and filter then?
the code they are using is perfectly fine besides the filter itself