recruitment/cr.py
async def command_newmember(self, ctx, member: discord.Member):
        """
            Setup nickname, and roles for a new member
        """
        guild = ctx.guild

        # if not (await self.bot.is_mod(ctx.author)):
        #     return await ctx.send(
        #         "Sorry! You do not have enough permissions to run this command."
        #     )

        # Check if user already has any of member roles:
        # Use `!changeclan` to change already registered member's clan cause it needs role checking to remove existing roles
        # if await self.discord_helper._is_member(member, guild=ctx.guild):
        #     return await ctx.send("Error, " + member.mention + " is not a new member.")

        is_clan_member = False
        try:
            player_tags = self.tags.getAllTags(member.id)
        except AttributeError:
            return await ctx.send("Cannot connect to database. Please notify the devs.")
        clans_joined = []
        clan_roles = []
        discord_invites = []
        clan_nicknames = []
        ign = ""
        if len(player_tags) == 0:
            return await ctx.send(
                "You must associate a tag with this member first using ``{}save #tag @member``".format(
                    ctx.prefix
                )
            )

        # Get a list of all family clans joined.
        try:
            for tag in player_tags:
                player_data = await self.clash.get_player(tag)
                if player_data.clan is None:
                    player_clan_tag = ""
                    player_clan_name = ""
                else:
                    player_clan_tag = player_data.clan.tag.strip("#")
                    player_clan_name = player_data.clan.name
                for name, data in self.family_clans.items():
                    if data["tag"] == player_clan_tag:
                        is_clan_member = True
                        clans_joined.append(name)
                        clan_roles.append(data["clanrole"])
                        clan_nicknames.append(data["nickname"])
                        if data.get("invite"):
                            discord_invites.append(data["invite"])
                # Set ign to first available name
                if not ign and player_data.name:
                    ign = player_data.name
        except clashroyale.RequestError:
            return await simple_embed(
                ctx, "Error: cannot reach Clash Royale Servers. Please try again later."
            )

        if ign:
            newname = ign
        else:
            return await simple_embed(ctx, "Cannot find ign for user.", False)

        output_msg = ""
        if is_clan_member:
            newclanname = " | ".join(clan_nicknames)
            newname += " | " + newclanname

            try:
                await member.edit(nick=newname)
            except discord.HTTPException:
                await simple_embed(
                    ctx, "I don't have permission to change nick for this user.", False
                )
            else:
                output_msg += "Nickname changed to **{}**\n".format(newname)

            clan_roles.append("Member")
            try:
                await self.discord_helper._add_roles(
                    member, clan_roles, reason="used newmember"
                )
                output_msg += f"**{humanize_list(clan_roles)}** roles added."
            except discord.Forbidden:
                await ctx.send(
                    "{} does not have permission to edit {}ΓÇÖs roles.".format(
                        ctx.author.display_name, member.display_name
                    )
                )
            except discord.HTTPException:
                await ctx.send(
                    "Failed to add roles {}.".format(humanize_list(clan_roles))
                )
            except InvalidRole:
                await ctx.send(
                    "Server roles are not setup properly. "
                    "Please check if you have {} roles in server.".format(
                        humanize_list(clan_roles)
                    )
                )
            if output_msg:
                await simple_embed(ctx, output_msg, True)

            # TODO: Add welcome message to global chat
            await self.discord_helper._remove_roles(
                member, ["Guest"], reason="used newmwmber"
            )

            roleName = discord.utils.get(guild.roles, name=clan_roles[0])
            recruitment_channel = self.bot.get_channel(
                await self.config.guild(ctx.guild).new_recruits_channel_id()
            )
            if recruitment_channel:
                await recruitment_channel.send(
                    "**{}** recruited **{} (#{})** to {}".format(
                        ctx.author.display_name, ign, tag, roleName.mention
                    ),
                    allowed_mentions=discord.AllowedMentions(
                        roles=(await self.config.guild(ctx.guild).mentions())["on_nm"]
                    ),
                )

            global_channel = self.bot.get_channel(
                await self.config.guild(ctx.guild).global_channel_id()
            )
            if global_channel:
                greeting_to_send = (random.choice(self.greetings)).format(member)
                await global_channel.send(
                    greeting_to_send,
                    allowed_mentions=discord.AllowedMentions(users=True),
                )

            try:
                await simple_embed(
                    member,
                    "Hi There! Congratulations on getting accepted into our family. "
                    "We have unlocked all the member channels for you in LeGeND Discord Server. "
                    "DM <@598662722821029888> if you have any problems.\n"
                    "Please do not leave our Discord server while you are in the clan. Thank you.",
                )
                if discord_invites:
                    await member.send(
                        (
                            "Please click on the link below to join your clan Discord server. \n\n"
                            "{invites}".format(invites="\n".join(discord_invites))
                            + "\n\n"
                            "Please do not leave our main or clan servers while you are in the clan. Thank you."
                        )
                    )

                await asyncio.sleep(60)
                for page in pagify(self.rules_text, delims=["\n\n\n"]):
                    await simple_embed(member, page)
                await asyncio.sleep(60)
                for page in pagify(self.esports_text, delims=["\n\n\n"]):
                    await member.send(page)
            except discord.errors.Forbidden:
                await ctx.send(
                    (
                        "{} please fix your privacy settings, "
                        "we are unable to send you Direct Messages.".format(
                            member.mention
                        )
                    ),
                    allowed_mentions=discord.AllowedMentions(users=True),
                )

        else:
            await ctx.send(
                "You must be accepted into a clan before I can give you clan roles. "
                "Would you like me to check again in 2 minutes? (Yes/No)"
            )
            pred = MessagePredicate.yes_or_no(ctx)
            await self.bot.wait_for("message", check=pred)
            if not pred.result:
                return
            await ctx.send("Okay, I will retry this command in 2 minutes.")
            await asyncio.sleep(120)
            message = ctx.message
            message.content = ctx.prefix + "newmember {}".format(member.mention)
            await self.bot.process_commands(message)

            Setup nickname, and roles for a new member
        
Setup nickname, and roles for a new member
Setup nickname and roles for a new member
async def command_newmember(self, ctx, member: discord.Member):
        guild = ctx.guild
        "Error, " + member.mention + " is not a new member.")
        is_clan_member = False
        try:
            player_tags = self.tags.getAllTags(member.id)
        except AttributeError:
            return await ctx.send("Cannot connect to database. Please notify the devs.")
        clans_joined = []
        clan_roles = []
        discord_invites = []
        clan_nicknames = []
        ign = ""
        if len(player_tags) == 0:
            return await ctx.send(
                "You must associate a tag with this member first using ``{}save #tag @member``".format(
                    ctx.prefix
                )
            )
        try:
            for tag in player_tags:
                player_data = await self.clash.get_player(tag)
                if player_data.clan is None:
                    player_clan_tag = ""
                    player_clan_name = ""
                else:
                    player_clan_tag = player_data.clan.tag.strip("#")
                    player_clan_name = player_data.clan.name
                for name, data in self.family_clans.items():
                    if data["tag"] == player_clan_tag:
                        is_clan_member = True
                        clans_joined.append(name)
                        clan_roles.append(data["clanrole"])
                        clan_nicknames.append(data["nickname"])
                        if data.get("invite"):
                            discord_invites.append(data["invite"])
                if not ign and player_data.name:
                    ign = player_data.name
        except clashroyale.RequestError:
            return await simple_embed(
                ctx, "Error: cannot reach Clash Royale Servers. Please try again later."
            )
        if ign:
            newname = ign
        else:
            return await simple_embed(ctx, "Cannot find ign for user.", False)
        output_msg = ""
        if is_clan_member:
            newclanname = " | ".join(clan_nicknames)
            newname += " | " + newclanname
            try:
                await member.edit(nick=newname)
            except discord.HTTPException:
                await simple_embed(
                    ctx, "I don't have permission to change nick for this user.", False
                )
            else:
                output_msg += "Nickname changed to **{}**\n".format(newname)
            clan_roles.append("Member")
            try:
                await self.discord_helper._add_roles(
                    member, clan_roles, reason="used newmember"
                )
                output_msg += f"**{humanize_list(clan_roles)}** roles added."
            except discord.Forbidden:
                await ctx.send(
                    "{} does not have permission to edit {}ΓÇÖs roles.".format(
                        ctx.author.display_name, member.display_name
                    )
                )
            except discord.HTTPException:
                await ctx.send(
                    "Failed to add roles {}.".format(humanize_list(clan_roles))
                )
            except InvalidRole:
                await ctx.send(
                    "Server roles are not setup properly. "
                    "Please check if you have {} roles in server.".format(
                        humanize_list(clan_roles)
                    )
                )
            if output_msg:
                await simple_embed(ctx, output_msg, True)
            await self.discord_helper._remove_roles(
                member, ["Guest"], reason="used newmwmber"
            )
            roleName = discord.utils.get(guild.roles, name=clan_roles[0])
            recruitment_channel = self.bot.get_channel(
                await self.config.guild(ctx.guild).new_recruits_channel_id()
            )
            if recruitment_channel:
                await recruitment_channel.send(
                    "**{}** recruited **{} (#{})** to {}".format(
                        ctx.author.display_name, ign, tag, roleName.mention
                    ),
                    allowed_mentions=discord.AllowedMentions(
                        roles=(await self.config.guild(ctx.guild).mentions())["on_nm"]
                    ),
                )
            global_channel = self.bot.get_channel(
                await self.config.guild(ctx.guild).global_channel_id()
            )
            if global_channel:
                greeting_to_send = (random.choice(self.greetings)).format(member)
                await global_channel.send(
                    greeting_to_send,
                    allowed_mentions=discord.AllowedMentions(users=True),
                )
            try:
                await simple_embed(
                    member,
                    "Hi There! Congratulations on getting accepted into our family. "
                    "We have unlocked all the member channels for you in LeGeND Discord Server. "
                    "DM <@598662722821029888> if you have any problems.\n"
                    "Please do not leave our Discord server while you are in the clan. Thank you.",
                )
                if discord_invites:
                    await member.send(
                        (
                            "Please click on the link below to join your clan Discord server. \n\n"
                            "{invites}".format(invites="\n".join(discord_invites))
                            + "\n\n"
                            "Please do not leave our main or clan servers while you are in the clan. Thank you."
                        )
                    )
                await asyncio.sleep(60)
                for page in pagify(self.rules_text, delims=["\n\n\n"]):
                    await simple_embed(member, page)
                await asyncio.sleep(60)
                for page in pagify(self.esports_text, delims=["\n\n\n"]):
                    await member.send(page)
            except discord.errors.Forbidden:
                await ctx.send(
                    (
                        "{} please fix your privacy settings, "
                        "we are unable to send you Direct Messages.".format(
                            member.mention
                        )
                    ),
                    allowed_mentions=discord.AllowedMentions(users=True),
                )
        else:
            await ctx.send(
                "You must be accepted into a clan before I can give you clan roles. "
                "Would you like me to check again in 2 minutes? (Yes/No)"
            )
            pred = MessagePredicate.yes_or_no(ctx)
            await self.bot.wait_for("message", check=pred)
            if not pred.result:
                return
            await ctx.send("Okay, I will retry this command in 2 minutes.")
            await asyncio.sleep(120)
            message = ctx.message
            message.content = ctx.prefix + "newmember {}".format(member.mention)
            await self.bot.process_commands(message)
async def command_newmember ( self , ctx , member : discord . Member ) : guild = ctx . guild is_clan_member = False try : player_tags = self . tags . getAllTags ( member . id ) except AttributeError : return await ctx . send ( "Cannot connect to database. Please notify the devs." ) clans_joined = [ ] clan_roles = [ ] discord_invites = [ ] clan_nicknames = [ ] ign = "" if len ( player_tags ) == 0 : return await ctx . send ( "You must associate a tag with this member first using ``{}save #tag @member``" . format ( ctx . prefix ) ) try : for tag in player_tags : player_data = await self . clash . get_player ( tag ) if player_data . clan is None : player_clan_tag = "" player_clan_name = "" else : player_clan_tag = player_data . clan . tag . strip ( "#" ) player_clan_name = player_data . clan . name for name , data in self . family_clans . items ( ) : if data [ "tag" ] == player_clan_tag : is_clan_member = True clans_joined . append ( name ) clan_roles . append ( data [ "clanrole" ] ) clan_nicknames . append ( data [ "nickname" ] ) if data . get ( "invite" ) : discord_invites . append ( data [ "invite" ] ) if not ign and player_data . name : ign = player_data . name except clashroyale . RequestError : return await simple_embed ( ctx , "Error: cannot reach Clash Royale Servers. Please try again later." ) if ign : newname = ign else : return await simple_embed ( ctx , "Cannot find ign for user." , False ) output_msg = "" if is_clan_member : newclanname = " | " . join ( clan_nicknames ) newname += " | " + newclanname try : await member . edit ( nick = newname ) except discord . HTTPException : await simple_embed ( ctx , "I don't have permission to change nick for this user." , False ) else : output_msg += "Nickname changed to **{}**\n" . format ( newname ) clan_roles . append ( "Member" ) try : await self . discord_helper . _add_roles ( member , clan_roles , reason = "used newmember" ) output_msg += f"**{humanize_list(clan_roles)}** roles added." except discord . Forbidden : await ctx . send ( "{} does not have permission to edit {}ΓÇÖs roles.".fo r mat( ctx . author . display_name , member . display_name ) ) except discord . HTTPException : await ctx . send ( "Failed to add roles {}." . format ( humanize_list ( clan_roles ) ) ) except InvalidRole : await ctx . send ( "Server roles are not setup properly. " "Please check if you have {} roles in server." . format ( humanize_list ( clan_roles ) ) ) if output_msg : await simple_embed ( ctx , output_msg , True ) await self . discord_helper . _remove_roles ( member , [ "Guest" ] , reason = "used newmwmber" ) roleName = discord . utils . get ( guild . roles , name = clan_roles [ 0 ] ) recruitment_channel = self . bot . get_channel ( await self . config . guild ( ctx . guild ) . new_recruits_channel_id ( ) ) if recruitment_channel : await recruitment_channel . send ( "**{}** recruited **{} (#{})** to {}" . format ( ctx . author . display_name , ign , tag , roleName . mention ) , allowed_mentions = discord . AllowedMentions ( roles = ( await self . config . guild ( ctx . guild ) . mentions ( ) ) [ "on_nm" ] ) , ) global_channel = self . bot . get_channel ( await self . config . guild ( ctx . guild ) . global_channel_id ( ) ) if global_channel : greeting_to_send = ( random . choice ( self . greetings ) ) . format ( member ) await global_channel . send ( greeting_to_send , allowed_mentions = discord . AllowedMentions ( users = True ) , ) try : await simple_embed ( member , "Hi There! Congratulations on getting accepted into our family. " "We have unlocked all the member channels for you in LeGeND Discord Server. " "DM <@598662722821029888> if you have any problems.\n" "Please do not leave our Discord server while you are in the clan. Thank you." , ) if discord_invites : await member . send ( ( "Please click on the link below to join your clan Discord server. \n\n" "{invites}" . format ( invites = "\n" . join ( discord_invites ) ) + "\n\n" "Please do not leave our main or clan servers while you are in the clan. Thank you." ) ) await asyncio . sleep ( 60 ) for page in pagify ( self . rules_text , delims = [ "\n\n\n" ] ) : await simple_embed ( member , page ) await asyncio . sleep ( 60 ) for page in pagify ( self . esports_text , delims = [ "\n\n\n" ] ) : await member . send ( page ) except discord . errors . Forbidden : await ctx . send ( ( "{} please fix your privacy settings, " "we are unable to send you Direct Messages." . format ( member . mention ) ) , allowed_mentions = discord . AllowedMentions ( users = True ) , ) else : await ctx . send ( "You must be accepted into a clan before I can give you clan roles. " "Would you like me to check again in 2 minutes? (Yes/No)" ) pred = MessagePredicate . yes_or_no ( ctx ) await self . bot . wait_for ( "message" , check = pred ) if not pred . result : return await ctx . send ( "Okay, I will retry this command in 2 minutes." ) await asyncio . sleep ( 120 ) message = ctx . message message . content = ctx . prefix + "newmember {}" . format ( member . mention ) await self . bot . process_commands ( message )
Setup nickname, and roles for a new member
Setup nickname and roles for a new member
"""
            Setup nickname, and roles for a new member
        """ # if not (await self.bot.is_mod(ctx.author)): #     return await ctx.send( #         "Sorry! You do not have enough permissions to run this command." #     ) # Check if user already has any of member roles: # Use `!changeclan` to change already registered member's clan cause it needs role checking to remove existing roles # if await self.discord_helper._is_member(member, guild=ctx.guild): #     return await ctx.send("Error, " + member.mention + " is not a new member.") # Get a list of all family clans joined. # Set ign to first available name # TODO: Add welcome message to global chat
self
ctx
member
discord.Member