/// <summary>
        /// Modifies an existing webhook.
        /// </summary>
        /// <exception cref="ArgumentException">Thrown if the token is empty or only contains whitespace characters.</exception>
        /// <exception cref="ArgumentNullException">Thrown if token is null.</exception>
        /// <exception cref="DiscordHttpApiException"></exception>
        public async Task ModifyWebhookWithToken(Snowflake webhookId, string token,
                                                 string name = null, DiscordImageData avatar = null)
        {
            if (token == null)
            {
                throw new ArgumentNullException(nameof(token));
            }
            if (string.IsNullOrWhiteSpace(token))
            {
                throw new ArgumentException("Token cannot be empty or only contain whitespace characters.", nameof(token));
            }

            DiscordApiData postData = DiscordApiData.CreateContainer();

            if (name != null)
            {
                postData.Set("name", name);
            }
            if (avatar != null)
            {
                postData.Set("avatar", avatar);
            }

            await rest.Patch($"webhooks/{webhookId}/{token}", postData,
                             $"webhooks/{webhookId}/token").ConfigureAwait(false);
        }
Exemplo n.º 2
0
        /// <exception cref="DiscordWebSocketException">Thrown if the payload fails to send because of a WebSocket error.</exception>
        /// <exception cref="InvalidOperationException">Thrown if the socket is not connected.</exception>
        public Task SendSelectProtocolPayload(string ip, int port, string encryptionMode)
        {
            DiscordApiData selectProtocol = new DiscordApiData();

            selectProtocol.Set("protocol", "udp");
            DiscordApiData data = selectProtocol.Set("data", DiscordApiData.CreateContainer());

            data.Set("address", ip);
            data.Set("port", port);
            data.Set("mode", encryptionMode);

            log.LogVerbose($"[SelectProtocol] Sending to {ip}:{port}...");
            return(SendPayload(VoiceOPCode.SelectProtocol, selectProtocol));
        }
        /// <summary>
        /// Creates a webhook.
        /// <para>Requires <see cref="DiscordPermission.ManageWebhooks"/>.</para>
        /// </summary>
        /// <param name="channelId">The ID of the channel the webhook will post to.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="name"/> or <paramref name="avatar"/> is null.</exception>
        /// <exception cref="DiscordHttpApiException"></exception>
        public async Task <DiscordWebhook> CreateWebhook(string name, DiscordImageData avatar, Snowflake channelId)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }
            if (avatar == null)
            {
                throw new ArgumentNullException(nameof(avatar));
            }

            DiscordApiData apiData = DiscordApiData.CreateContainer();

            apiData.Set("name", name);
            apiData.Set("avatar", avatar);

            DiscordApiData returnData = await rest.Post($"channels/{channelId}/webhooks", apiData,
                                                        $"channels/{channelId}/webhooks").ConfigureAwait(false);

            return(new DiscordWebhook(this, returnData));
        }
        /// <summary>
        /// Modifies an existing webhook.
        /// <para>Requires <see cref="DiscordPermission.ManageWebhooks"/>.</para>
        /// </summary>
        /// <param name="channelId">The ID of the text channel to move the webhook to (or null to not move).</param>
        /// <exception cref="DiscordHttpApiException"></exception>
        public async Task <DiscordWebhook> ModifyWebhook(Snowflake webhookId,
                                                         string name = null, DiscordImageData avatar = null, Snowflake?channelId = null)
        {
            DiscordApiData postData = DiscordApiData.CreateContainer();

            if (name != null)
            {
                postData.Set("name", name);
            }
            if (avatar != null)
            {
                postData.Set("avatar", avatar);
            }
            if (channelId.HasValue)
            {
                postData.SetSnowflake("channel_id", channelId.Value);
            }

            DiscordApiData apiData = await rest.Patch($"webhooks/{webhookId}", postData,
                                                      $"webhooks/{webhookId}").ConfigureAwait(false);

            return(new DiscordWebhook(this, apiData));
        }