What is the best way to get all the messages in a channel? My current method is consistently getting me rate limited every other message. #129
Answered
by
swarley
quinton-oglesby
asked this question in
Q&A
-
My current method of doing so looks like this, but surely there is a better way of doing this? I have 1.5 million messages I'm trying to scrape and if I keep having to put my bot to sleep every five seconds to avoid rate limiting then that is going to take nearly 90 days. |
Beta Was this translation helpful? Give feedback.
Answered by
swarley
Jan 30, 2022
Replies: 1 comment
-
Answered in discord bot = Discordrb::Bot.new(token: ENV['INOSUKE_TOKEN']);
after_id = 0
message_store = []
while (messages = bot.channel(345687437722386433).history(100, nil, after_id)).count == 100
after_id = messages.map(&:id).max
puts "new after #{after_id}"
message_store += messages # or do whatever you want to do with the messages to avoid keeping them in memory
end
# and you'll need to handle the last set of messages again out here, or use a flag set inside of the loop for continuing instead |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
swarley
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Answered in discord