Example #1
0
        static void Main()
        {
            //Create a client with the token
            Console.Write("Token: ");
            DiscordClient client = new DiscordClient(Console.ReadLine());

            //find the guild
            Console.Write($"Guild id: ");
            Guild targetGuild = client.GetGuild(long.Parse(Console.ReadLine()));
            Guild ourGuild = DuplicateGuild(client, targetGuild);

            DeleteAllChannels(client, ourGuild);

            List<RoleDupe> ourRoles = DuplicateRoles(client, targetGuild, ourGuild);

            #region create channels
            OrganizedChannelList channels = new OrganizedChannelList(targetGuild.GetChannels());

            Console.WriteLine("Duplicating categories...");

            //duplicate category channels
            List<CategoryDupe> ourCategories = new List<CategoryDupe>();
            foreach (var c in channels.Categories)
            {
                GuildChannel category;

                try
                {
                    category = client.GetGuildChannel(c.Id);
                }
                catch (DiscordHttpErrorException e)
                {
                    //ofcourse you could make it return no matter what error, but this is better for debugging
                    if (e.Error.Code == 50001)
                        continue;
                    else
                        throw;
                }

                //create the category
                GuildChannel ourCategory = ourGuild.CreateChannel(new ChannelCreationProperties() { Name = category.Name, Type = ChannelType.Category });
                ourCategory.Modify(new GuildChannelProperties() { Position = category.Position });

                foreach (var overwrite in category.PermissionOverwrites)
                {
                    if (overwrite.Type == PermissionOverwriteType.Member)
                        continue;

                    PermissionOverwrite ourOverwrite = overwrite;
                    ourOverwrite.Id = ourRoles.First(ro => ro.TargetRole.Id == overwrite.Id).OurRole.Id;
                    ourCategory.AddPermissionOverwrite(ourOverwrite);
                }

                CategoryDupe dupe = new CategoryDupe
                {
                    TargetCategory = category,
                    OurCategory = ourCategory
                };
                ourCategories.Add(dupe);

                Console.WriteLine($"Duplicated {category.Name}");

                Thread.Sleep(50);
            }

            Console.WriteLine("Duplicating channels...");

            //duplicate text channels
            foreach (var c in channels.TextChannels)
            {
                TextChannel channel;

                try
                {
                    channel = client.GetTextChannel(c.Id);
                }
                catch (DiscordHttpErrorException e)
                {
                    //ofcourse you could make it return no matter what error, but this is better for debugging
                    if (e.Error.Code == 50001)
                        continue;
                    else
                        throw;
                }

                TextChannel ourChannel = ourGuild.CreateTextChannel(new ChannelCreationProperties() { Name = channel.Name, ParentId = channel.ParentId != null ? (long?)ourCategories.First(ca => ca.TargetCategory.Id == channel.ParentId).OurCategory.Id : null });
                ourChannel.Modify(new TextChannelProperties() { Nsfw = channel.Nsfw, Position = channel.Position, Topic = channel.Topic, SlowMode = channel.SlowMode });

                foreach (var overwrite in channel.PermissionOverwrites)
                {
                    if (overwrite.Type == PermissionOverwriteType.Member)
                        continue;

                    PermissionOverwrite ourOverwrite = overwrite;
                    ourOverwrite.Id = ourRoles.First(ro => ro.TargetRole.Id == overwrite.Id).OurRole.Id;
                    ourChannel.AddPermissionOverwrite(ourOverwrite);
                }

                Console.WriteLine($"Duplicated {channel.Name}");

                Thread.Sleep(50);
            }

            //duplicate voice channels
            foreach (var c in channels.VoiceChannels)
            {
                VoiceChannel channel;

                try
                {
                    channel = client.GetVoiceChannel(c.Id);
                }
                catch (DiscordHttpErrorException e)
                {
                    //ofcourse you could make it return no matter what error, but this is better for debugging
                    if (e.Error.Code == 50001)
                        continue;
                    else
                        throw;
                }


                //create voice channels
                VoiceChannel ourChannel = ourGuild.CreateVoiceChannel(new ChannelCreationProperties() { Name = channel.Name, ParentId = channel.ParentId != null ? (long?)ourCategories.First(ca => ca.TargetCategory.Id == channel.ParentId).OurCategory.Id : null });
                ourChannel.Modify(new VoiceChannelProperties() { Bitrate = channel.Bitrate, Position = channel.Position, UserLimit = channel.UserLimit });

                foreach (var overwrite in channel.PermissionOverwrites)
                {
                    if (overwrite.Type == PermissionOverwriteType.Member)
                        continue;

                    PermissionOverwrite ourOverwrite = overwrite;
                    ourOverwrite.Id = ourRoles.First(ro => ro.TargetRole.Id == overwrite.Id).OurRole.Id;
                    ourChannel.AddPermissionOverwrite(ourOverwrite);
                }

                Console.WriteLine($"Duplicated {channel.Name}");

                Thread.Sleep(100);
            }
            #endregion

            Console.WriteLine("Done!");
            Console.ReadLine();
        }
Example #2
0
        private static void DuplicateChannels(Guild targetGuild, Guild ourGuild, List <RoleDupe> ourRoles)
        {
            OrganizedChannelList channels = new OrganizedChannelList(targetGuild.GetChannels());

            Console.WriteLine("Duplicating categories...");

            //duplicate category channels
            List <CategoryDupe> ourCategories = new List <CategoryDupe>();

            foreach (var category in channels.Categories)
            {
                //create the category
                GuildChannel ourCategory = ourGuild.CreateChannel(category.Name, ChannelType.Category);
                ourCategory.Modify(new GuildChannelProperties()
                {
                    Position = category.Position
                });

                foreach (var overwrite in category.PermissionOverwrites)
                {
                    if (overwrite.Type == PermissionOverwriteType.Member)
                    {
                        continue;
                    }

                    DiscordPermissionOverwrite ourOverwrite = overwrite;
                    ourOverwrite.Id = ourRoles.First(ro => ro.TargetRole.Id == overwrite.Id).OurRole.Id;
                    ourCategory.AddPermissionOverwrite(ourOverwrite);
                }

                CategoryDupe dupe = new CategoryDupe
                {
                    TargetCategory = category,
                    OurCategory    = ourCategory
                };
                ourCategories.Add(dupe);

                Console.WriteLine($"Duplicated {category.Name}");
            }

            Console.WriteLine("Duplicating channels...");

            //duplicate text channels
            foreach (var c in channels.TextChannels)
            {
                TextChannel channel = c.ToTextChannel();

                TextChannel ourChannel = ourGuild.CreateChannel(channel.Name, ChannelType.Text, channel.ParentId != null ? (ulong?)ourCategories.First(ca => ca.TargetCategory.Id == channel.ParentId).OurCategory.Id : null).ToTextChannel();
                ourChannel.Modify(new TextChannelProperties()
                {
                    Nsfw = channel.Nsfw, Position = channel.Position, Topic = channel.Topic, SlowMode = channel.SlowMode
                });

                foreach (var overwrite in channel.PermissionOverwrites)
                {
                    if (overwrite.Type == PermissionOverwriteType.Member)
                    {
                        continue;
                    }

                    DiscordPermissionOverwrite ourOverwrite = overwrite;
                    ourOverwrite.Id = ourRoles.First(ro => ro.TargetRole.Id == overwrite.Id).OurRole.Id;
                    ourChannel.AddPermissionOverwrite(ourOverwrite);
                }

                Console.WriteLine($"Duplicated {channel.Name}");
            }

            //duplicate voice channels
            foreach (var channel in channels.VoiceChannels)
            {
                //create voice channels
                VoiceChannel ourChannel = ourGuild.CreateChannel(channel.Name, ChannelType.Voice, channel.ParentId != null ? (ulong?)ourCategories.First(ca => ca.TargetCategory.Id == channel.ParentId).OurCategory.Id : null).ToVoiceChannel();
                ourChannel.Modify(new VoiceChannelProperties()
                {
                    Bitrate = channel.Bitrate, Position = channel.Position, UserLimit = channel.UserLimit
                });

                foreach (var overwrite in channel.PermissionOverwrites)
                {
                    if (overwrite.Type == PermissionOverwriteType.Member)
                    {
                        continue;
                    }

                    DiscordPermissionOverwrite ourOverwrite = overwrite;
                    ourOverwrite.Id = ourRoles.First(ro => ro.TargetRole.Id == overwrite.Id).OurRole.Id;
                    ourChannel.AddPermissionOverwrite(ourOverwrite);
                }

                Console.WriteLine($"Duplicated {channel.Name}");
            }
        }
Example #3
0
        private static void DuplicateChannels(DiscordClient client, Guild targetGuild, Guild ourGuild, List <RoleDupe> ourRoles)
        {
            OrganizedChannelList channels = new OrganizedChannelList(targetGuild.GetChannels());

            Console.WriteLine("Duplicating categories...");

            //duplicate category channels
            List <CategoryDupe> ourCategories = new List <CategoryDupe>();

            foreach (var c in channels.Categories)
            {
                GuildChannel category;

                try
                {
                    category = client.GetGuildChannel(c.Id);
                }
                catch (DiscordHttpException e)
                {
                    //ofcourse you could make it return no matter what error, but this is better for debugging
                    if (e.Code == DiscordError.MissingAccess)
                    {
                        continue;
                    }
                    else
                    {
                        throw;
                    }
                }

                //create the category
                GuildChannel ourCategory = ourGuild.CreateChannel(new GuildChannelCreationProperties()
                {
                    Name = category.Name, Type = ChannelType.Category
                });
                ourCategory.Modify(new GuildChannelProperties()
                {
                    Position = category.Position
                });

                foreach (var overwrite in category.PermissionOverwrites)
                {
                    if (overwrite.Type == PermissionOverwriteType.Member)
                    {
                        continue;
                    }

                    PermissionOverwrite ourOverwrite = overwrite;
                    ourOverwrite.Id = ourRoles.First(ro => ro.TargetRole.Id == overwrite.Id).OurRole.Id;
                    ourCategory.AddPermissionOverwrite(ourOverwrite);
                }

                CategoryDupe dupe = new CategoryDupe
                {
                    TargetCategory = category,
                    OurCategory    = ourCategory
                };
                ourCategories.Add(dupe);

                Console.WriteLine($"Duplicated {category.Name}");

                Thread.Sleep(50);
            }

            Console.WriteLine("Duplicating channels...");

            //duplicate text channels
            foreach (var c in channels.TextChannels)
            {
                TextChannel channel;

                try
                {
                    channel = client.GetTextChannel(c.Id);
                }
                catch (DiscordHttpException e)
                {
                    //ofcourse you could make it return no matter what error, but this is better for debugging
                    if (e.Code == DiscordError.MissingAccess)
                    {
                        continue;
                    }
                    else
                    {
                        throw;
                    }
                }

                TextChannel ourChannel = ourGuild.CreateTextChannel(new GuildChannelCreationProperties()
                {
                    Name = channel.Name, ParentId = channel.ParentId != null ? (ulong?)ourCategories.First(ca => ca.TargetCategory.Id == channel.ParentId).OurCategory.Id : null
                });
                ourChannel.Modify(new TextChannelProperties()
                {
                    Nsfw = channel.Nsfw, Position = channel.Position, Topic = channel.Topic, SlowMode = channel.SlowMode
                });

                foreach (var overwrite in channel.PermissionOverwrites)
                {
                    if (overwrite.Type == PermissionOverwriteType.Member)
                    {
                        continue;
                    }

                    PermissionOverwrite ourOverwrite = overwrite;
                    ourOverwrite.Id = ourRoles.First(ro => ro.TargetRole.Id == overwrite.Id).OurRole.Id;
                    ourChannel.AddPermissionOverwrite(ourOverwrite);
                }

                Console.WriteLine($"Duplicated {channel.Name}");

                Thread.Sleep(50);
            }

            //duplicate voice channels
            foreach (var c in channels.VoiceChannels)
            {
                VoiceChannel channel;

                try
                {
                    channel = client.GetVoiceChannel(c.Id);
                }
                catch (DiscordHttpException e)
                {
                    //ofcourse you could make it return no matter what error, but this is better for debugging
                    if (e.Code == DiscordError.MissingAccess)
                    {
                        continue;
                    }
                    else
                    {
                        throw;
                    }
                }


                //create voice channels
                VoiceChannel ourChannel = ourGuild.CreateVoiceChannel(new GuildChannelCreationProperties()
                {
                    Name = channel.Name, ParentId = channel.ParentId != null ? (ulong?)ourCategories.First(ca => ca.TargetCategory.Id == channel.ParentId).OurCategory.Id : null
                });
                ourChannel.Modify(new VoiceChannelProperties()
                {
                    Bitrate = channel.Bitrate, Position = channel.Position, UserLimit = channel.UserLimit
                });

                foreach (var overwrite in channel.PermissionOverwrites)
                {
                    if (overwrite.Type == PermissionOverwriteType.Member)
                    {
                        continue;
                    }

                    PermissionOverwrite ourOverwrite = overwrite;
                    ourOverwrite.Id = ourRoles.First(ro => ro.TargetRole.Id == overwrite.Id).OurRole.Id;
                    ourChannel.AddPermissionOverwrite(ourOverwrite);
                }

                Console.WriteLine($"Duplicated {channel.Name}");

                Thread.Sleep(50);
            }
        }