mirror of
https://onedev.fprog.nl/DiscordClient
synced 2025-12-28 20:38:36 +01:00
Added Methods to send and delete messages.
This commit is contained in:
parent
ef94c1b3c9
commit
94da458afd
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue