public static async Task SendMessageAsync(string _Content, string ChannelID) { RemcordRest client = new RemcordRest(); RemcordAuthentication authx = new RemcordAuthentication(); authx.Token = tokenx.GetToken(); MessagePayload payload = new MessagePayload(); payload.Content = _Content; await Task.Run(() => { client.SendPostRequest(EndpointRoutes.POST_SendMessage(ChannelID), payload, authx); }); }
/// <summary> /// Sends a request using the specified method through REST. /// </summary> /// <returns>The response from Discord.</returns> /// <param name="EndpointTarget">Discord API endpoint to send to.</param> /// <param name="Payload">Payload to send.</param> /// <param name="Method">Method.</param> /// <param name="Authentication">Most endpoints require authentication.</param> public IRestResponse SendRequest(string EndpointTarget, MessagePayload Payload, Method Method, RemcordAuthentication Authentication) { RestClient RequestClient = new RestClient("https://discordapp.com/api"); RestRequest Request = new RestRequest(EndpointTarget, Method); Request.JsonSerializer = new RemcordJsonSerializer(); Request.AddJsonBody(Payload); if (Authentication != null) { Request.AddHeader("Authorization", "Bot " + Authentication.Token); } IRestResponse Response = RequestClient.Execute(Request); return(Response); }
/// <summary> /// Sends a POST request using SendRequest. /// </summary> /// <returns>The response from Discord.</returns> /// <param name="EndpointTarget">Discord API endpoint to send to.</param> /// <param name="Payload">Payload to send.</param> /// <param name="Authentication">Most endpoints require authentication.</param> public IRestResponse SendPostRequest(string EndpointTarget, MessagePayload Payload, RemcordAuthentication Authentication) => SendRequest(EndpointTarget, Payload, Method.POST, Authentication);