コード例 #1
0
        private async Task <RestTextChannel> CreateTextChannelAsync(RestGuild guild, string courseName, RequestOptions requestOptions, ulong roleId)
        {
            // prevent duplicate under this category
            foreach (var channel in await guild.GetChannelsAsync())
            {
                if (channel.Name.Equals(courseName, StringComparison.OrdinalIgnoreCase) && channel is RestCategoryChannel restCategory && restCategory.Id == CategoryId)
                {
                    // there's a match under this category
                    return(null);
                }
            }

            var category = await guild.GetChannelAsync(CategoryId);

            var overwriteList = new List <Overwrite>();

            overwriteList.AddRange(category.PermissionOverwrites);
            overwriteList.Add(new Overwrite(guild.EveryoneRole.Id, PermissionTarget.Role, new Discord.OverwritePermissions(viewChannel: Discord.PermValue.Deny)));
            overwriteList.Add(new Overwrite(roleId, PermissionTarget.Role, new Discord.OverwritePermissions(viewChannel: Discord.PermValue.Allow)));

            var result = await guild.CreateTextChannelAsync(courseName, options =>
            {
                options.CategoryId           = CategoryId;
                options.Topic                = $"Course channel for {courseName}";
                options.PermissionOverwrites = overwriteList;
            }, options : requestOptions);

            return(result);
        }
コード例 #2
0
        public async Task <IChannel> GetChannel(ulong channelId, RestGuild guild = null)
        {
            if (guild != null)
            {
                return(await guild.GetChannelAsync(channelId));
            }

            IChannel channel;

            try
            {
                channel = await this._restClient.GetChannelAsync(channelId);
            }
            catch
            {
                Log.Warning($"RestClient couldn't get channel: {channelId}");
                channel = this._client.GetChannel(channelId);
            }
            return(channel);
        }