public async Task AddEmote(string emoji, string roleName) { var db = new DatabaseContext(); var role = Context.Guild.Roles.FirstOrDefault(x => x.Name.Equals(roleName)); var server = db.Servers.Include(x => x.Options).ThenInclude(x => x.RoleEmotes).FirstOrDefault(x => x.ServerId == (long)Context.Guild.Id); if (role != null && server != null) { var obj = new RoleEmote(); obj.DiscordRole = (long)role.Id; var name = emoji.Replace(":", ""); Console.WriteLine(name); Console.WriteLine(Context.Guild.Emotes.First().Name); var emote = Context.Guild.Emotes.FirstOrDefault(x => name.Contains(x.Id.ToString())); obj.Emote = (long)emote.Id; server.Options.RoleEmotes.Add(obj); db.Servers.Update(server); db.SaveChanges(); IUserMessage message = null; foreach (var textChannel in Context.Guild.GetTextChannelsAsync().Result) { try { message = (IUserMessage)await textChannel.GetMessageAsync( (ulong)server.Options.RoleEmoteMessageId); if (message != null) { break; } } catch { } } if (message != null) { ServerContainer.DeleteCache(); await ReplyAsync($"{emoji} was been added for role " + role.Name); await message.AddReactionAsync(emote); } } }
static Emotes() { try { RoleEmoteList = new RoleEmote[] { new RoleEmote(Emote.Parse("<:ds1:368332018838405121>"), Roles.DS1), new RoleEmote(Emote.Parse("<:ds1r:488412792207179797>"), Roles.DSR), new RoleEmote(Emote.Parse("<:ds2:368334686319017985>"), Roles.DS2), new RoleEmote(Emote.Parse("<:ds2sotfs:368335262377312266>"), Roles.SOTFS), new RoleEmote(Emote.Parse("<:ds3:368334983250837504>"), Roles.DS3), new RoleEmote(Emote.Parse("<:Xbox360:368388223354798081>"), Roles.XB360), new RoleEmote(Emote.Parse("<:XboxOne:369570227337428993>"), Roles.XB1), new RoleEmote(Emote.Parse("<:PS3:368380526253441024>"), Roles.PS3), new RoleEmote(Emote.Parse("<:PS4:368380645858344961>"), Roles.PS4), new RoleEmote(Emote.Parse("<:PC:368373647213068300>"), Roles.PC), new RoleEmote(Emote.Parse("<:Switch:368388237367967744>"), Roles.SWITCH) }; } catch (Exception e) { Console.Out.WriteLine(e); Console.Out.WriteLine("This is probably very bad."); } }