import json import requests as req xivAPI_link = "https://xivapi.com/freecompany/9234349560946624156?data=fcm" FCroleName = 'Bolinho' FCroleID = 1016945192126906368 whitelisted = ['85091960884322304'] ### # THIS ASSUMES THAT EVERYONE IN YOUR DISCORD USES THEIR CHARACTER NAME AS THEIR NICKNAMES AS ENFORCED BY OTHER FFXIV RELATED BOTS VERIFICATION METHOD ### ###################### # REMOVE ROLE CROSS CHECK ###################### @client.command(name="remove") async def update(context): if str(context.message.author.id) in whitelisted: url = req.get(xivAPI_link) #gets FC information text = url.text data = json.loads(text) listaFFXIV = [] member = data['FreeCompanyMembers'] #Creates a lis with the FC members. for x in range(0,len(member)): listaFFXIV += list(member[x].values())[4].split(",") # For each fc member, gets value [4] (character name) await context.message.channel.send("Member list populated with a total of "+str(len(listaFFXIV))+" members.") #sends a message on the channel with the amount of members in the list. #print('\n'.join(listaFFXIV)) listaDISCORD = [] role = discord.utils.get(context.message.guild.roles, name=FCroleName) #Gets Discord Role information if role is None: #If role doesn't exist, then exit. return empty = True for member in context.message.guild.members: # Goes through every discord member if role in member.roles: # if member has your FC role listaDISCORDusr = "{}".format(member.nick) # gets member nickname usr = ''.join(listaDISCORDusr) # concatenates member nickname (couldn't find another way to do this) if usr != 'None': # ignore user if he does not have a nickname, otherwise listaDISCORD.append(usr) # adds that user to a list await context.message.channel.send("Encontrados "+str(len(listaDISCORD))+" bolinhos com o cargo") # announces i nthe chanel how many people have your FC role remover = [user for user in listaDISCORD if user not in listaFFXIV] # For every member that has your role but is not in your FC, creates a new list lista = [] cargo = context.guild.get_role(FCroleID) # gets role info for entry in remover: # for every user in the removal list usuario = discord.utils.get(context.guild.members, nick=entry) # gets their discord user info through their nickname await usuario.remove_roles(cargo) # remove their role print(f'Removed {role} from {entry}') # print statement lista.append(usuario.mention) # converts nickname list to mentions await context.message.channel.send('Removido cargo dos seguintes membros: \n'+'\n'.join(lista)) # sends said list on a channel so you can double check if everything went well. empty = False if empty: print("There is no one") return ###################### # ADD ROLE CROSS CHECK ###################### @client.command(name="add") async def update(context): if str(context.message.author.id) in whitelisted: url = req.get(xivAPI_link) # gets fc information text = url.text data = json.loads(text) listaFFXIV = [] member = data['FreeCompanyMembers'] # creates member list from FC for x in range(0,len(member)): listaFFXIV += list(member[x].values())[4].split(",") # gets their character names await context.message.channel.send("Member list populated with a total of "+str(len(listaFFXIV))+" members.") listaDISCORD = [] role = discord.utils.get(context.message.guild.roles, name=FCroleName) # gets role info if role is None: # if no role then exit return empty = True for member in context.message.guild.members: # for every user in your discord if role not in member.roles: # if user DOES NOT have your FC role listaDISCORDusr = "{}".format(member.nick) # gets their nickname usr = ''.join(listaDISCORDusr) # again, just a fix I couldn't find another way to do if usr != 'None': # if no nickname ignore, otherwise listaDISCORD.append(usr) # adds that user to a list await context.message.channel.send("Found "+str(len(listaDISCORD))+" users without the role") # announces how many users there are without your fc role adicionar = [user for user in listaFFXIV if user in listaDISCORD] # for every user in XIV not with discord role, creates a third list lista = [] cargo = context.guild.get_role(FCroleID) for entry in adicionar: usuario = discord.utils.get(context.guild.members, nick=entry) await usuario.add_roles(cargo) print(f'Added {role} to {entry}') lista.append(usuario.mention) # converts list into mention list await context.message.channel.send('I have given the FC role to the following Discord Users: \n'+'\n'.join(lista)) # anounces who got the role empty = False if empty: print("There is no one") return