Пример #1
0
        /// <summary>
        /// Modifies this member.
        /// </summary>
        /// <param name="action">Action to perform on this member.</param>
        /// <returns></returns>
        public async Task ModifyAsync(Action <MemberEditModel> action)
        {
            var mdl = new MemberEditModel();

            action(mdl);

            if (mdl.VoiceChannel.HasValue && mdl.VoiceChannel.Value.Type != ChannelType.Voice)
            {
                throw new ArgumentException("Given channel is not a voice channel.", nameof(mdl.VoiceChannel));
            }

            if (mdl.Nickname.HasValue && this.Discord.CurrentUser.Id == this.Id)
            {
                await this.Discord.ApiClient.ModifyCurrentMemberNicknameAsync(this.Guild.Id, mdl.Nickname.Value,
                                                                              mdl.AuditLogReason).ConfigureAwait(false);

                await this.Discord.ApiClient.ModifyGuildMemberAsync(this.Guild.Id, this.Id, Optional <string> .FromNoValue(),
                                                                    mdl.Roles.IfPresent(e => e.Select(xr => xr.Id)), mdl.Muted, mdl.Deafened,
                                                                    mdl.VoiceChannel.IfPresent(e => e.Id), mdl.AuditLogReason).ConfigureAwait(false);
            }
            else
            {
                await this.Discord.ApiClient.ModifyGuildMemberAsync(this.Guild.Id, this.Id, mdl.Nickname,
                                                                    mdl.Roles.IfPresent(e => e.Select(xr => xr.Id)), mdl.Muted, mdl.Deafened,
                                                                    mdl.VoiceChannel.IfPresent(e => e.Id), mdl.AuditLogReason).ConfigureAwait(false);
            }
        }
Пример #2
0
 /// <summary>
 /// Edits the message.
 /// </summary>
 /// <param name="content">New content.</param>
 /// <param name="embed">New embed.</param>
 /// <returns></returns>
 /// <exception cref="Exceptions.UnauthorizedException">Thrown when the client tried to modify a message not sent by them.</exception>
 /// <exception cref="Exceptions.NotFoundException">Thrown when the member does not exist.</exception>
 /// <exception cref="Exceptions.BadRequestException">Thrown when an invalid parameter was provided.</exception>
 /// <exception cref="Exceptions.ServerErrorException">Thrown when Discord is unable to process the request.</exception>
 public Task <DiscordMessage> ModifyAsync(Optional <string> content, Optional <DiscordEmbed> embed = default)
 => this.Discord.ApiClient.EditMessageAsync(this.ChannelId, this.Id, content, embed, default);
Пример #3
0
 /// <summary>
 /// Sends a message to this channel.
 /// </summary>
 /// <param name="content">Content of the message to send.</param>
 /// <param name="tts">Whether the message is to be read using TTS.</param>
 /// <param name="embed">Embed to attach to the message.</param>
 /// <returns>The sent message.</returns>
 public Task <DiscordMessage> SendMessageAsync(Optional <string> content = default(Optional <string>), bool tts = false, Optional <DiscordEmbed> embed = default(Optional <DiscordEmbed>)) =>
 this.Discord.ApiClient.CreateMessageAsync(Id, content, tts, embed);