Reputation: 1
Im trying to make a Discord C# Command That uses Discords new Timeout function using discord.NET
I tried using HTTP Requests instead cause i couldnt find a discord.NET function but It returns an unauthorized error
public static async Task PatchData(string url, string data, string token)
{
// Create a new HttpClient instance
using var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Authorization",token);
httpClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
var content = new StringContent(data, Encoding.UTF8, "application/json");
var response = await httpClient.PatchAsync(url, content);
if (response.IsSuccessStatusCode)
{
Console.WriteLine("Data patched successfully!");
}
else
{
Console.WriteLine(response.StatusCode);
}
}
and for the execution
await Patch.PatchData($"https://discord.com/api/v9/guilds/{Context.Guild.Id}/members/{user.Id}",
"{\"communication_disabled_until\": "
+ current_time + time_in_minutes + "}",botToken);
Upvotes: 0
Views: 450
Reputation: 52
There is a special awaitable for this
var time = new TimeSpan(0, 0, 0);
await Your_IGuildUser.SetTimeOutAsync(span: time);
Check if you are updated to the lastest version.
Also i think discord usually will not accept random HTTP request resulting in authorized error but it is just my assumption.
Upvotes: 0