Exemple #1
0
        public async Task ReorderChannelAsync(CommandContext ctx,
                                              [Description("Channel to reposition.")] DiscordChannel channel,
                                              [Description("New position.")] int position,
                                              [RemainingText, Description("Reason.")] string reason = null)
        {
            if (position < 0)
            {
                throw new ArgumentException("Position cannot be negative.", nameof(position));
            }

            channel = channel ?? ctx.Channel;

            await channel.ModifyPositionAsync(position, ctx.BuildInvocationDetailsString(reason));

            await this.InformAsync(ctx, $"Changed the position of channel {Formatter.Bold(channel.Name)} to {Formatter.Bold(position.ToString())}", important : false);
        }
        async Task <(bool, string)> CreateClass(CommandContext context)
        {
            string errorMessage = string.Empty;
            bool   success      = true;

            DiscordChannel categoryChannel = await _channel.Guild.CreateChannelAsync($"{_courseCategory} {_courseNumber} {_courseTitle}", ChannelType.Category);

            DiscordRole categoryRole = await _channel.Guild.CreateRoleAsync($"{_courseCategory} {_courseNumber}", ALLOWED);

            // if you do not modify the position - it will end up at the bottom of the channel list
            await categoryChannel.ModifyPositionAsync(await GetSortPosition());

            await categoryChannel.AddOverwriteAsync(categoryRole, ALLOWED, Permissions.Administrator);

            await categoryChannel.AddOverwriteAsync(everyone, Permissions.None, DENIED);

            // Apply all roles that were found in the config (to our category)
            foreach (DiscordRole role in this.additionalRoles)
            {
                await categoryChannel.AddOverwriteAsync(role, ALLOWED, Permissions.None);
            }

            // Create each specified channel within the config
            foreach (string channelName in _options.ChannelNames)
            {
                await CreateTextChannel(categoryChannel, $"{_courseCategory} {_courseNumber}", channelName);
            }

            // Create voice channels based on config
            for (int i = 0; i < _options.NumberOfVoiceChannels; i++)
            {
                _ = await _channel.Guild.CreateChannelAsync($"{_courseCategory} {_courseNumber} - {i + 1}", ChannelType.Voice, parent : categoryChannel);
            }

            return(success, errorMessage);
        }