コード例 #1
0
        /// <summary>
        /// Sends a message to a specified channel.
        /// </summary>
        /// <param name="_Content">String to send</param>
        /// <param name="ChannelID">Channel ID to send message to.</param>
        public static void SendMessage(string _Content, string ChannelID)
        {
            RemcordRest           rc = new RemcordRest();
            RemcordAuthentication a  = new RemcordAuthentication();

            a.Token = tokenx.GetToken();
            MessagePayload p = new MessagePayload();

            p.Content = _Content;
            rc.SendPostRequest(EndpointRoutes.POST_SendMessage(ChannelID), p, a);
        }
コード例 #2
0
        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);
            });
        }
コード例 #3
0
 /// <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);
コード例 #4
0
        /// <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);
        }
コード例 #5
0
 /// <summary>
 /// Updates the current authentication set.
 /// </summary>
 /// <param name="_Authentication">Authentication to replace the current one with.</param>
 public void UpdateAuthentication(RemcordAuthentication _Authentication)
 {
     Authentication = _Authentication;
 }