public async Task recievebroadcast() { await _BDB.NewGuild(Context.Guild.Id, Context.Channel.Id); IGuild s = await Context.Client.GetGuildAsync(_SS.USRGuildId); ITextChannel ch = await s.GetTextChannelAsync(_SS.LogId); await ReplyAsync(":thumbsup:, `;broadcasthelp` for further info."); await ch.SendMessageAsync($"**{Context.Guild.Name}** has registered their guild to recieve broadcasts."); }
public async Task Start() { // Define the DiscordSocketClient client = new DiscordSocketClient(); var token = "nope. Bad idea that I stored it in plaintext tho lol."; ss = new SandwichService(); client.Log += async(message) => { await Log(message); }; client.JoinedGuild += async(m) => { IGuild usr = client.GetGuild(ss.USRGuildId); ITextChannel usrc = await usr.GetTextChannelAsync(ss.LogId); var e = new EmbedBuilder(); e.Color = new Color(94, 180, 255); e.ThumbnailUrl = m.IconUrl; e.Timestamp = DateTime.Now; e.Description = $"I have joined **{m.Name}**(`{m.Id}`) \r\n" + $"That is **{m.Users.Count}** new users. \r\n" + $"I am now in **{client.Guilds.Count}** servers!"; await usrc.SendMessageAsync("", embed : e); var textchannel = m.GetTextChannel(m.Channels.Where(c => m.CurrentUser.GetPermissions(c).SendMessages) .OrderBy(c => c.Position) .FirstOrDefault().Id); ss.Load(); await textchannel.SendMessageAsync(ss.motd); await bdb.NewGuild(m.Id, textchannel.Id); await bdb.SaveChangesAsync(); if (!m.CurrentUser.GuildPermissions.CreateInstantInvite) { await m.DefaultChannel.SendMessageAsync(":warning: The bot cannot create instant invites! Please give the bot permission or else it will not work! :warning: "); } }; client.LeftGuild += async(m) => { await bdb.RemoveGuild(m.Id); IGuild usr = client.GetGuild(ss.USRGuildId); ITextChannel usrc = await usr.GetTextChannelAsync(ss.LogId); var e = new EmbedBuilder(); e.Color = new Color(232, 34, 34); e.ThumbnailUrl = m.IconUrl; e.Timestamp = DateTime.Now; e.Description = $"I have left **{m.Name}**(`{m.Id}`)! \r\n" + $"That is **{m.Users.Count}** less users. \r\n" + $"I am now in **{client.Guilds.Count}** servers..."; await usrc.SendMessageAsync("", embed : e); }; client.MessageReceived += async(m) => { if (m.Author.IsBot) { return; } if (m.Channel.Id == client.CurrentUser.Id) { return; } if (m.MentionedUsers.Any(u => u.Id == client.CurrentUser.Id)) { if (m.Content.Contains("help")) { await m.Channel.SendMessageAsync("Type `;help`. `;server` if you have any problems."); } } var rnd = new Random(); var r = rnd.Next(1, 25); if (r == 2) { var totalChannels = 0; var totalUsers = 0; foreach (var obj in client.Guilds) { totalChannels = totalChannels + obj.Channels.Count; totalUsers = totalUsers + obj.Users.Count; } await client.SetGameAsync($"{totalChannels} channels with a total of {totalUsers} users. | Type ;motd for help"); } if (r == 6) { await client.SetGameAsync($" {client.Guilds.Count()} servers. | Type ;motd for help"); } }; var serviceProvider = ConfigureServices(); //var timer = new System.Threading.Timer(async (e) => //{ // await VerifyTransactionsAsync(); //}, null, 0, (int)TimeSpan.FromMinutes(0.5).TotalMilliseconds); // Login and connect to Discord. handler = new CommandHandler(); await handler.Install(serviceProvider); await client.LoginAsync(TokenType.Bot, token); await client.StartAsync(); // Block this program until it is closed. await Task.Delay(-1); }