Example #1
0
        /// <exception cref="ArgumentNullException"><paramref name="name"/> is <c>null</c>.</exception>
        public static async Task <RestVoiceChannel> CreateVoiceChannelAsync(IGuild guild, BaseDiscordClient client,
                                                                            string name, RequestOptions options, Action <VoiceChannelProperties> func = null)
        {
            if (name == null)
            {
                throw new ArgumentNullException(paramName: nameof(name));
            }

            var props = new VoiceChannelProperties();

            func?.Invoke(props);

            var args = new CreateGuildChannelParams(name, ChannelType.Voice)
            {
                CategoryId = props.CategoryId,
                Bitrate    = props.Bitrate,
                UserLimit  = props.UserLimit,
                Position   = props.Position,
                Overwrites = props.PermissionOverwrites.IsSpecified
                    ? props.PermissionOverwrites.Value.Select(overwrite => new API.Overwrite
                {
                    TargetId   = overwrite.TargetId,
                    TargetType = overwrite.TargetType,
                    Allow      = overwrite.Permissions.AllowValue.ToString(),
                    Deny       = overwrite.Permissions.DenyValue.ToString()
                }).ToArray()
                    : Optional.Create <API.Overwrite[]>(),
            };
            var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false);

            return(RestVoiceChannel.Create(client, guild, model));
        }
Example #2
0
 internal static RestGuildChannel Create(BaseDiscordClient discord, IGuild guild, Model model)
 {
     return(model.Type switch
     {
         ChannelType.News => RestNewsChannel.Create(discord, guild, model),
         ChannelType.Text => RestTextChannel.Create(discord, guild, model),
         ChannelType.Voice => RestVoiceChannel.Create(discord, guild, model),
         ChannelType.Stage => RestStageChannel.Create(discord, guild, model),
         ChannelType.Category => RestCategoryChannel.Create(discord, guild, model),
         ChannelType.PublicThread or ChannelType.PrivateThread or ChannelType.NewsThread => RestThreadChannel.Create(discord, guild, model),
         _ => new RestGuildChannel(discord, guild, model.Id),
     });
Example #3
0
        public static async Task <RestVoiceChannel> CreateVoiceChannelAsync(IGuild guild, BaseDiscordClient client,
                                                                            string name, RequestOptions options)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            var args  = new CreateGuildChannelParams(name, ChannelType.Voice);
            var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false);

            return(RestVoiceChannel.Create(client, guild, model));
        }
Example #4
0
        internal static RestGuildChannel Create(BaseDiscordClient discord, IGuild guild, Model model)
        {
            switch (model.Type)
            {
            case ChannelType.Text:
                return(RestTextChannel.Create(discord, guild, model));

            case ChannelType.Voice:
                return(RestVoiceChannel.Create(discord, guild, model));

            default:
                throw new InvalidOperationException("Unknown guild channel type");
            }
        }
        internal static RestGuildChannel Create(BaseDiscordClient discord, IGuild guild, Model model)
        {
            switch (model.Type)
            {
            case ChannelType.Text:
                return(RestTextChannel.Create(discord, guild, model));

            case ChannelType.Voice:
                return(RestVoiceChannel.Create(discord, guild, model));

            default:
                // TODO: Channel categories
                return(new RestGuildChannel(discord, guild, model.Id));
            }
        }
Example #6
0
        /// <exception cref="ArgumentNullException"><paramref name="name"/> is <c>null</c>.</exception>
        public static async Task <RestVoiceChannel> CreateVoiceChannelAsync(IGuild guild, BaseDiscordClient client,
                                                                            string name, RequestOptions options, Action <VoiceChannelProperties> func = null)
        {
            if (name == null)
            {
                throw new ArgumentNullException(paramName: nameof(name));
            }

            var props = new VoiceChannelProperties();

            func?.Invoke(props);

            var args = new CreateGuildChannelParams(name, ChannelType.Voice)
            {
                CategoryId = props.CategoryId,
                Bitrate    = props.Bitrate,
                UserLimit  = props.UserLimit
            };
            var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false);

            return(RestVoiceChannel.Create(client, guild, model));
        }