public async Task RemoveRole(SocketRole _role) { if (_role != null) { var msg = Context.Message; await msg.DeleteAsync(); var user = Context.User; var role = Context.Guild.Roles.FirstOrDefault(x => x.Name == _role.ToString()); await(user as IGuildUser).RemoveRoleAsync(role); await ReplyAsync("The role " + role.Mention + " has been removed from user <@" + user.Id + ">"); } }
public async Task GiveRole(SocketRole _role) { var fxs = Context.Guild.Roles.FirstOrDefault(x => x.Name == "FengXiaoStan"); var ywss = Context.Guild.Roles.FirstOrDefault(x => x.Name == "Yan Wushi Squad"); var member = Context.Guild.Roles.FirstOrDefault(x => x.Name == "member"); if (_role == fxs || _role == ywss || _role == member) { var msg = Context.Message; await msg.DeleteAsync(); var user = Context.User; var role = Context.Guild.Roles.FirstOrDefault(x => x.Name == _role.ToString()); await(user as IGuildUser).AddRoleAsync(role); await ReplyAsync("<@" + user.Id + "> has been given the role " + role.Mention); } }
public async Task colorRole(SocketRole role) { if (role.Permissions.Administrator || role.Name == "gangsta") { return; } else if (role.Position >= 10) { return; } else { try { var r = Context.Guild.Roles.FirstOrDefault(x => x.Name == role.ToString()); if ((Context.User as SocketGuildUser).Roles.Contains(r)) { try { await(Context.User as SocketGuildUser).RemoveRoleAsync(r); await ReplyAsync("You remove your color!"); } catch { Console.WriteLine("not found?"); await ReplyAsync("Remove color role failed. Role not found."); } } else { try { await(Context.User as SocketGuildUser).AddRoleAsync(r); await ReplyAsync("Your color is now " + role.Mention); } catch { Console.WriteLine("not found?"); await ReplyAsync("Adding color role failed. Role not found."); } } } catch { Console.WriteLine("error"); } } }
public Task AddReactionAsync(ulong messageID, SocketGuildChannel channel, Emoji emote, SocketRole role) { Context.Message.AddReactionAsync(new Discord.Emoji("👍")); if (channel.Guild.Id != Context.Guild.Id || role.Guild.Id != Context.Guild.Id) { return(ReplyAsync("Error! Trying to add ReactionRole to a different server!")); } else if (channel.Guild.Id != role.Guild.Id) { return(ReplyAsync("Error! Channel and role are not from the same server!")); } lock (Data.ReactionRoles) Data.ReactionRoles.Add(new ReactionRole((channel as SocketGuildChannel).Guild.Id, messageID, emote.Name, role.Id)); Data.Save(); //TODO - Add emote reaction to specified message return(ReplyAsync("Success - " + role.ToString() + " will be added based on " + emote.ToString() + " reactions in the specified channel")); }
public async Task whosIn([Remainder] SocketRole r) { List <string> UserList = new List <string>(); List <string> UserListSorted = new List <string>(); var m = r.Members; foreach (var v in m) { string buffer = ""; string status = " | [" + HelperFunctions.UserStatus.getStatus(v).ToUpper() + "]"; if (v.Nickname != "" || v.Nickname != null || v.Nickname != " " || v.Nickname != v.Username) { buffer = ", *\"" + v.Nickname + "\"*"; } if (buffer == ", *\"\"*") { UserList.Add(v.Username + status); } else { UserList.Add(v.Username + buffer + status); } } UserList.Sort(); //need a new list to number them in sorted order for (int i = 0; i < UserList.Count(); i++) { UserListSorted.Add(("__**" + (i + 1) + "**__") + ": " + UserList[i] + Environment.NewLine); } #region Split Array List <string[]> splitted = new List <string[]>();//This list will contain all the splitted arrays. int lengthToSplit = 25; int arrayLength = UserListSorted.Count; for (int i = 0; i < arrayLength; i = i + lengthToSplit) { string[] val = new string[lengthToSplit]; if (arrayLength < i + lengthToSplit) { lengthToSplit = arrayLength - i; } Array.Copy(UserListSorted.ToArray(), i, val, 0, lengthToSplit); splitted.Add(val); } #endregion //embed builder if (UserListSorted.Count() > 1) { await Context.Channel.SendMessageAsync("__**There are " + UserListSorted.Count() + " members in " + r.ToString() + ":**__"); for (int i = 0; i < splitted.Count; i++) { await Context.Channel.SendMessageAsync(Environment.NewLine + Environment.NewLine + string.Join("", splitted[i])); } return; } else if (UserListSorted.Count() == 1) { await Context.Channel.SendMessageAsync("__**There is 1 member in " + r.ToString() + ":**__" + Environment.NewLine + Environment.NewLine + string.Join("", UserListSorted)); return; } else { await Context.Channel.SendMessageAsync("__**There is no one in " + r.ToString() + ":**__"); return; } }