mirror of
https://onedev.fprog.nl/DiscordClient
synced 2025-12-28 16:58:37 +01:00
30 lines
893 B
C#
30 lines
893 B
C#
using System.Net.Http.Headers;
|
|
using System.Net.Http.Json;
|
|
using DiscordClient.Data;
|
|
|
|
namespace DiscordClient;
|
|
|
|
public class DiscordUserClient
|
|
{
|
|
private readonly HttpClient _httpClient;
|
|
|
|
public DiscordUserClient(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[]>();
|
|
}
|
|
}
|