#How to get all messages in channel?

1 messages · Page 1 of 1 (latest)

gray arrow
#

I don't think you can get all messages

#

Not at once at least

mellow aspen
#

I'm trying to do the same thing at the moment, I've made a bit of headway

#

This is what I have so far

public static async Task Scrape(SocketSlashCommand cmd) {
    SocketTextChannel channel = (SocketTextChannel)cmd.Data.Options.First().Value;

    Console.WriteLine($"Scraping {channel}");

    IMessage[] messages = (await channel.GetMessagesAsync()
        .FlattenAsync()).ToArray();

    for (int i = 0; i < messages.Length; i++) {
        Console.WriteLine(messages[i]);
    }

    await cmd.RespondAsync($"Scraped {channel}", ephemeral: true);
}
#

The only caveats are 1. I have to tell it how many messages get (or scrape) and 2. I don't have any way of knowing if that command option corresponds to a VC or an actual text channel

#

Which means that cast is a bit unsafe

gray arrow
mellow aspen
#

yeah there's a type for text channels and vcs, i just haven't gotten around to it lol

thorny osprey
#

I mean VCs are pretty much text channels now, so it doesn't really matter if all you want is to get their chat messages

mellow aspen
#

true

mellow aspen
#

don't know what happens if you make it get more messages than there are in a channel

#

i'll try it in a couple hours, gotta do some things first

mellow aspen
#

apparently my definition of "a couple hours" actually means a day and a half, anyways

#

this works perfectly fine, funnily enough

#

just tested it, it gave me all messages with zero issues