Added Methods to send and delete messages.

This commit is contained in:
Filip Strajnar 2024-03-15 22:42:33 +01:00
parent ef94c1b3c9
commit 94da458afd

View file

@ -1,5 +1,6 @@
using System.Net.Http.Headers;
using System.Net.Http.Json;
using System.Text.Json.Serialization;
using DiscordClient.Data;
namespace DiscordClient;
@ -26,4 +27,30 @@ public class DiscordUserClient
HttpResponseMessage response = await _httpClient.GetAsync(url);
return await response.Content.ReadFromJsonAsync<ChannelMessagesResponse[]>();
}
sealed class MessageContent
{
[JsonPropertyName("content")]
public string Content { get; set; }
}
/// <summary>
/// This method does NOT work yet.
/// </summary>
/// <param name="channelId"></param>
/// <param name="message"></param>
/// <returns></returns>
public async Task<HttpResponseMessage> SendMessage(string channelId, string message)
{
throw new NotImplementedException();
string url = $"https://discord.com/api/v9/channels/{channelId}/messages";
HttpContent httpContent = JsonContent.Create(new MessageContent{Content = message});
return await _httpClient.PostAsync(url, httpContent);
}
public async Task<HttpResponseMessage> DeleteMessage(string channelId, string messageId)
{
string url = $"https://discord.com/api/v9/channels/{channelId}/messages/{messageId}";
return await _httpClient.DeleteAsync(url);
}
}