diff --git a/src/Discord.Net/API/Endpoints.cs b/src/Discord.Net/API/Endpoints.cs
index 2ff2711bc..eae381cbd 100644
--- a/src/Discord.Net/API/Endpoints.cs
+++ b/src/Discord.Net/API/Endpoints.cs
@@ -16,8 +16,8 @@
public static string ChannelInvites(string channelId) => $"channels/{channelId}/invites";
public static string ChannelMessages(string channelId) => $"channels/{channelId}/messages";
public static string ChannelMessages(string channelId, int limit) => $"channels/{channelId}/messages?limit={limit}";
- public static string ChannelMessages(string channelId, int limit, string beforeId) => $"channels/{channelId}/messages?limit={limit}&before={beforeId}";
- public static string ChannelMessage(string channelId, string msgId) => $"channels/{channelId}/messages/{msgId}";
+ public static string ChannelMessages(string channelId, int limit, string relativeId, string relativeDir) => $"channels/{channelId}/messages?limit={limit}&{relativeDir}={relativeId}";
+ public static string ChannelMessage(string channelId, string msgId) => $"channels/{channelId}/messages/{msgId}";
public static string ChannelMessageAck(string channelId, string msgId) => $"channels/{channelId}/messages/{msgId}/ack";
public static string ChannelPermission(string channelId, string userOrRoleId) => $"channels/{channelId}/permissions/{userOrRoleId}";
public static string ChannelTyping(string channelId) => $"channels/{channelId}/typing";
diff --git a/src/Discord.Net/DiscordAPIClient.cs b/src/Discord.Net/DiscordAPIClient.cs
index f547d81f7..9bcab8461 100644
--- a/src/Discord.Net/DiscordAPIClient.cs
+++ b/src/Discord.Net/DiscordAPIClient.cs
@@ -1,5 +1,4 @@
using Discord.API;
-using Discord.Net;
using Discord.Net.Rest;
using System;
using System.Collections.Generic;
@@ -9,6 +8,8 @@ using System.Threading.Tasks;
namespace Discord
{
+ public enum RelativeDirection { Before, After }
+
/// A lightweight wrapper around the Discord API.
public class DiscordAPIClient
{
@@ -92,12 +93,12 @@ namespace Discord
var request = new ReorderChannelsRequest(channels);
return _rest.Patch(Endpoints.ServerChannels(serverId), request);
}
- public Task GetMessages(string channelId, int count, string beforeMessageId = null)
+ public Task GetMessages(string channelId, int count, string relativeMessageId = null, RelativeDirection relativeDir = RelativeDirection.Before)
{
if (channelId == null) throw new ArgumentNullException(nameof(channelId));
- if (beforeMessageId != null)
- return _rest.Get(Endpoints.ChannelMessages(channelId, count, beforeMessageId));
+ if (relativeMessageId != null)
+ return _rest.Get(Endpoints.ChannelMessages(channelId, count, relativeMessageId, relativeDir == RelativeDirection.Before ? "before" : "after"));
else
return _rest.Get(Endpoints.ChannelMessages(channelId, count));
}
diff --git a/src/Discord.Net/DiscordClient.Messages.cs b/src/Discord.Net/DiscordClient.Messages.cs
index 27f84265f..b2522e93c 100644
--- a/src/Discord.Net/DiscordClient.Messages.cs
+++ b/src/Discord.Net/DiscordClient.Messages.cs
@@ -215,8 +215,9 @@ namespace Discord
catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { }
}
- /// Downloads last count messages from the server, starting at beforeMessageId if it's provided.
- public async Task DownloadMessages(Channel channel, int count, string beforeMessageId = null, bool cache = true)
+
+ /// Downloads last count messages from the server, returning all messages before or after relativeMessageId, if it's provided.
+ public async Task DownloadMessages(Channel channel, int count, string relativeMessageId = null, RelativeDirection relativeDir = RelativeDirection.Before, bool cache = true)
{
if (channel == null) throw new ArgumentNullException(nameof(channel));
if (count < 0) throw new ArgumentNullException(nameof(count));
@@ -227,8 +228,8 @@ namespace Discord
{
try
{
- var msgs = await _api.GetMessages(channel.Id, count, beforeMessageId).ConfigureAwait(false);
- return msgs.Select(x =>
+ var msgs = await _api.GetMessages(channel.Id, count, relativeMessageId, relativeDir).ConfigureAwait(false);
+ var result = msgs.Select(x =>
{
Message msg = null;
if (cache)