Exemplo n.º 1
0
        /// <summary>
        /// Send a webhook object to the discord api asynchronously
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public async Task SendAsync(WebhookObject obj)
        {
            try
            {
                var json = new StringContent(obj.ToString(), Encoding.UTF8, "application/json");

                await webhookClient.PostAsync(_url, json);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// sends a webhookobject to the discord webhook used mostly for embeds
        /// </summary>
        /// <param name="obj">the webhook object</param>
        public void Send(WebhookObject obj)
        {
            try
            {
                obj.username   = _username == null ? obj.username : _username;
                obj.avatar_url = _username == null ? obj.avatar_url : _avatarurl;
                var json = new StringContent(obj.ToString(), Encoding.UTF8, "application/json");

                webhookClient.PostAsync(_url, json).GetAwaiter().GetResult();
            }
            catch (Exception e)
            {
                throw e;
            }
        }