Example #1
0
        /// <summary>
        ///     Gets the named Channel.
        ///     <para>
        ///         If createIfDoesNotExist is true the Category and the Channel itself
        ///         will be created if found to be missing and the Channel returned to the caller.
        ///     </para>
        /// </summary>
        /// <param name="context"></param>
        /// <param name="categoryName"></param>
        /// <param name="channelName"></param>
        /// <param name="createIfDoesNotExist"></param>
        /// <returns></returns>
        public static async Task <SocketTextChannel> GetTextChannel(this SocketCommandContext context,
                                                                    string categoryName, string channelName, bool createIfDoesNotExist = false)
        {
            SocketTextChannel product;
            var parent = await context.GetCategory(categoryName, createIfDoesNotExist);

            product = (SocketTextChannel)parent.Channels.SingleOrDefault(ch => ch.Name == channelName);

            if (product == null && createIfDoesNotExist)
            {
                var rest = await context.Guild.CreateTextChannelAsync(channelName,
                                                                      opts => { opts.CategoryId = parent.Id; });

                product = context.Guild.GetTextChannel(rest.Id);
            }

            return(product);
        }