private async Task OnGuildJoin(SocketGuild guild) { await Task.Run(async() => { try { DatabaseContext context = new DatabaseContext(); if (!(context.Auth.Any(o => o.Serverid == guild.Id) && (!(context.OnJoin.Any(o => o.Serverid == guild.Id))))) { string warning = null; try { if (guild.Roles.Any(x => x.Name == "Fork-Mods")) { foreach (var Role in guild.Roles.Where(x => x.Name == "Fork-Mods")) { await Role.DeleteAsync(); } } } catch (Exception ex) { warning += $"`Fork-Mods` role detected, please move my role above the `Fork-Mods` role and authenticate using `$auth [token]` then run `$rec` to clean it." + Environment.NewLine; } try { if (guild.TextChannels.Any(x => x.Name == "Fork-Bot")) { foreach (var Chan in guild.Channels.Where(x => x.Name == "Fork-Bot")) { await Chan.DeleteAsync(); } } } catch (Exception ex) { warning += $"`Fork-Bot` channel detected, please move my role above the `Fork-Mods` role and authenticate using `$auth [token]` then run `$rec` to clean it." + Environment.NewLine; } if (warning == null) { ulong origin = (ulong)GuildPermission.Speak + (ulong)GuildPermission.SendTTSMessages + (ulong)GuildPermission.SendMessages + (ulong)GuildPermission.ViewChannel + (ulong)GuildPermission.EmbedLinks + (ulong)GuildPermission.Connect + (ulong)GuildPermission.AttachFiles + (ulong)GuildPermission.AddReactions; GuildPermissions perms = new GuildPermissions(origin); //Color Colorr = new Color(21, 22, 34); var roleee = await guild.CreateRoleAsync("Fork-Mods", perms, null, false, false, null); var vChan = await guild.CreateTextChannelAsync("Fork-Bot"); await vChan.AddPermissionOverwriteAsync(roleee, AdminPermissions()); await vChan.AddPermissionOverwriteAsync(guild.EveryoneRole, NoPermissions()); var ebd = new EmbedBuilder(); ebd.Color = Color.Green; ebd.WithCurrentTimestamp(); ebd.WithAuthor($"Fork Server Management", guild.CurrentUser.GetAvatarUrl()); ebd.WithDescription( "Hello there," + Environment.NewLine + "I'm Fork Bot if you don't know me, I can help you control your Fork Minecraft servers and display their status in Discord." + Environment.NewLine + "I made a private channel for you, please use `$auth [token]` to link this Discord server with your Fork app." + Environment.NewLine + "You can check for your token in Fork app settings."); //var ownerr = KKK.Client.GetGuild(guild.Id).OwnerId; await vChan.SendMessageAsync($"<@{guild.OwnerId}>", false, ebd.Build()); var msgg = await vChan.SendMessageAsync(null, false, BotTools.Embed("Don't remove this message, this message will be updated continuously and display the status of you Fork servers.", 20)); using (var contextt = new DatabaseContext()) { OnJoin newset = new OnJoin(); newset.Serverid = guild.Id; newset.Roleid = roleee.Id; newset.Channelid = vChan.Id; newset.Messageid = msgg.Id; contextt.Add(newset); contextt.SaveChanges(); } } else { var ebd = new EmbedBuilder(); ebd.Color = Color.Red; ebd.WithCurrentTimestamp(); ebd.WithAuthor($"Error", guild.CurrentUser.GetAvatarUrl()); ebd.WithDescription(warning); //var ownerr = KKK.Client.GetGuild(guild.Id).OwnerId; await guild.DefaultChannel.SendMessageAsync($"<@{guild.OwnerId}>", false, ebd.Build()); } } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }); }