Support large DeleteMessages collections
This commit is contained in:
@@ -181,8 +181,22 @@ namespace Discord.Rest
|
||||
public static async Task DeleteMessagesAsync(IMessageChannel channel, BaseDiscordClient client,
|
||||
IEnumerable<IMessage> messages, RequestOptions options)
|
||||
{
|
||||
var args = new DeleteMessagesParams(messages.Select(x => x.Id).ToArray());
|
||||
await client.ApiClient.DeleteMessagesAsync(channel.Id, args, options).ConfigureAwait(false);
|
||||
var msgs = messages.Select(x => x.Id).ToArray();
|
||||
if (msgs.Length < 100)
|
||||
{
|
||||
var args = new DeleteMessagesParams(msgs);
|
||||
await client.ApiClient.DeleteMessagesAsync(channel.Id, args, options).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
var batch = new ulong[100];
|
||||
for (int i = 0; i < (msgs.Length + 99) / 100; i++)
|
||||
{
|
||||
Array.Copy(msgs, i * 100, batch, 0, Math.Min(msgs.Length - (100 * i), 100));
|
||||
var args = new DeleteMessagesParams(batch);
|
||||
await client.ApiClient.DeleteMessagesAsync(channel.Id, args, options).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Permission Overwrites
|
||||
|
||||
Reference in New Issue
Block a user