mirror of
https://onedev.fprog.nl/DiscordClient
synced 2025-12-28 13:28:37 +01:00
New method on DiscordClient.
This commit is contained in:
parent
386a993531
commit
5bfe7e2714
3
DiscordClient/Data/ChannelMessagesResponse.cs
Normal file
3
DiscordClient/Data/ChannelMessagesResponse.cs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
namespace DiscordClient.Data;
|
||||
|
||||
public class ChannelMessagesResponse { }
|
||||
|
|
@ -1,5 +1,29 @@
|
|||
namespace DiscordClient;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Net.Http.Json;
|
||||
using DiscordClient.Data;
|
||||
|
||||
namespace DiscordClient;
|
||||
|
||||
public class DiscordClient
|
||||
{
|
||||
}
|
||||
private readonly HttpClient _httpClient;
|
||||
|
||||
public DiscordClient(string authorizationToken)
|
||||
{
|
||||
_httpClient = new HttpClient();
|
||||
_httpClient.DefaultRequestHeaders.Host = "discord.com";
|
||||
_httpClient.DefaultRequestHeaders.Authorization = AuthenticationHeaderValue.Parse(
|
||||
authorizationToken
|
||||
);
|
||||
}
|
||||
|
||||
public async Task<ChannelMessagesResponse[]?> GetChannelMessages(
|
||||
string channelId,
|
||||
int limit = 50
|
||||
)
|
||||
{
|
||||
string url = $"https://discord.com/api/v9/channels/{channelId}/messages?limit={limit}";
|
||||
HttpResponseMessage response = await _httpClient.GetAsync(url);
|
||||
return await response.Content.ReadFromJsonAsync<ChannelMessagesResponse[]>();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue