Exemplo n.º 1
0
        /// <summary>
        /// Registers a webhook with this client. This retrieves a webhook based on the ID and token supplied.
        /// </summary>
        /// <param name="id">The ID of the webhook to add.</param>
        /// <param name="token">The token of the webhook to add.</param>
        /// <returns>The registered webhook.</returns>
        public async Task <DiscordWebhook> AddWebhookAsync(ulong id, string token)
        {
            if (string.IsNullOrWhiteSpace(token))
            {
                throw new ArgumentNullException(nameof(token));
            }
            token = token.Trim();

            if (_hooks.Any(x => x.Id == id))
            {
                throw new InvalidOperationException("This webhook is registered with this client.");
            }

            var wh = await _apiclient.GetWebhookWithTokenAsync(id, token).ConfigureAwait(false);

            _hooks.Add(wh);

            return(wh);
        }