Ask coding questions

← Back to all posts
cyclomatic complexity too high: 21 (threshold 15)
ZaddyDanger (0)

The code just stops working. Is there any way to not get this error?

Comments
hotnewtop
SixBeeps (5047)

See here.

This isn't an error, but rather a warning. Your code doesn't work because of something else. Mind linking a Repl?

ZaddyDanger (0)

@SixBeeps It works if I run it on my PC. But it doesn't when I run on replit.

ZaddyDanger (0)

@SixBeeps It is a discord bot command.

    @commands.command(aliases=["sinfo", "si"])
    async def serverinfo(self, ctx):
        server = ctx.message.guild

        tonline = 0
        for i in server.members:
            if str(i.status) == 'online' or str(i.status) == 'idle' or str(
                    i.status) == 'dnd':
                tonline += 1

        online = 0
        for i in server.members:
            if str(i.status) == 'online':
                online += 1

        idle = 0
        for i in server.members:
            if str(i.status) == 'idle':
                idle += 1

        dnd = 0
        for i in server.members:
            if str(i.status) == 'dnd':
                dnd += 1

        offline = 0
        for i in server.members:
            if str(i.status) == 'offline':
                offline += 1

        channel_count = len([
            x for x in server.channels
            if type(x) == discord.channel.TextChannel
        ])

        role_count = len(server.roles)
        emoji_count = len(server.emojis)
        voice_count = len([
            y for y in server.channels
            if type(y) == discord.channel.VoiceChannel
        ])
        if server.system_channel:
            sysc = server.system_channel.mention
        else:
            sysc = "None"
        if server.afk_channel:
            afkc = server.afk_channel
            afkt = f"{int(server.afk_timeout/60)} minutes"
        else:
            afkc = "Not Set"
            afkt = "AFK Channel not set"

        bot_count = 0
        for member in server.members:
            if member.bot:
                bot_count += 1
        humans = server.member_count - bot_count

        if str(server.region) == "sydney":
            flag1 = ":flag_au:"
            fln = "Sydney"
        elif str(server.region) == "india":
            flag1 = ":flag_in:"
            fln = "India"
        elif str(server.region) == "us-central":
            flag1 = ":flag_us:"
            fln = "US Central"
        elif str(server.region) == "us-east":
            flag1 = ":flag_us:"
            fln = "US East"
        elif str(server.region) == "us-west":
            flag1 = ":flag_us:"
            fln = "US West"
        elif str(server.region) == "us-south":
            flag1 = ":flag_us:"
            fln = "US South"
        elif str(server.region) == "brazil":
            flag1 = ":flag_br:"
            fln = "Brazil"
        elif str(server.region) == "russia":
            flag1 = ":flag_ru:"
            fln = "Russia"
        elif str(server.region) == "europe":
            flag1 = ":flag_eu:"
            fln = "Europe"
        elif str(server.region) == "hongkong":
            flag1 = ":flag_hk:"
            fln = "Hong Kong"
        elif str(server.region) == "japan":
            flag1 = ":flag_jp:"
            fln = "Japan"
        elif str(server.region) == "singapore":
            flag1 = ":flag_sg:"
            fln = "Singapore"
        elif str(server.region) == "southafrica":
            flag1 = ":flag_za:"
            fln = "South Africa"
        else:
            flag1 = "\u200b"
            fln = "None"
        temote = int((server.emoji_limit) * 2)

        create = datetime.date(server.created_at)
        today = datetime.date(ctx.message.created_at)
        age = today - create
        dayz = age.days
        year = dayz / 365
        remainder = dayz % 365
        week = remainder / 7
        day = remainder % 7
        server_age = f"**{int(year)}** years **{int(week)}** weeks \n **{int(day)}** days"

        em = discord.Embed(title=f"**{server.name}**", color=ctx.author.color)
        em.add_field(
            name=
            '<a:s1:745843568614178886>__Server ID__<a:s2:745843646011670649>',
            value=server.id,
            inline=True)
        em.add_field(name='<a:owner:745641366045851688> __Owner__:',
                     value=f"{server.owner.name} **[{server.owner.mention}]**",
                     inline=True)
        em.add_field(name="\u200b", value="\u200b", inline=True)
        em.add_field(name='<a:create1:745839243267407953> __Created At__:',
                     value=server.created_at.__format__(
                         '**%d. %B %Y** \nTime: **%H:%M:%S** \nDay: **%A**'),
                     inline=True)
        em.add_field(
            name=
            '<:wi1:745840689731993662>__Server Age__<:wi2:745840661353201744>',
            value=f"{server_age} \n(**{dayz}** days ago)",
            inline=True)
        em.add_field(name="\u200b", value="\u200b", inline=True)
        em.add_field(
            name="-----------------------------------------------------",
            value="\u200b",
            inline=False)
        em.add_field(name='<a:earth:743330109758636075> __Region__:',
                     value=f"➤ {flag1} {fln}",
                     inline=True)
        em.add_field(
            name='<a:verify:745640158229037218> __Verification Level__:',
            value=f"➤ {str(server.verification_level).capitalize()}")
        em.add_field(name="\u200b", value="\u200b", inline=True)
        em.add_field(name='<a:heart11:745845813066072157> __Members__:',
                     value=f'''⁍Total Users: **{int(server.member_count)}**
⁍Humans: **{int(humans)}**
⁍Bots: **{int(bot_count)}**''',
                     inline=True)
        em.add_field(
            name='<a:statusm:745842497745584218>__Member Status__:',
            value=f'''➤ Active: **{int(tonline)}/{int(server.member_count)}**
<:online:745518164120698990> **{int(online)}** | <:idle:745518192696229918> **{int(idle)}** | <:dnd:745518219908874270> **{int(dnd)}** 
<:offline:745518131807649832> **{int(offline)}**''',
            inline=True)
        em.add_field(name="\u200b", value="\u200b", inline=True)
        em.add_field(name='<a:roles:745846445197754499> __Number of roles__:',
                     value=f"➤ {str(role_count)} role(s)")
        em.add_field(name='<a:id1:745835682932457516> __Highest Role__:',
                     value=f"➤ {server.roles[-1].mention}")
        em.add_field(name="\u200b", value="\u200b", inline=True)
        em.add_field(name='<a:text:745833207643111515> __Text Channels__:',
                     value=f"➤ {str(channel_count)} Channel(s)",
                     inline=True)
        em.add_field(name='<a:voice2:745838598024200214> __Voice Channels__:',
                     value=f"➤ {str(voice_count)} Channel(s)",
                     inline=True)
        em.add_field(name="\u200b", value="\u200b", inline=True)
        em.add_field(
            name="-----------------------------------------------------",
            value="\u200b",
            inline=False)
        em.add_field(name='<a:misc:745832620541214760> __Misc__:',
                     value=f'''⁍AFK Channel: 
**{afkc}**
⁍AFK Timeout: 
**{afkt}**
⁍System Channel: 
{sysc}
⁍Total Custom Emojis: 
**{int(emoji_count)}**''',
                     inline=True)
        em.add_field(name='<a:boost:745625750216114227> __Nitro Boost__:',
                     value=f'''⁍Server Level: **{server.premium_tier}**
⁍No. of Boosts: **{server.premium_subscription_count}**
⁍Emoji Slots left: **{int((temote)-(emoji_count))}/{temote}**
⁍File size limit: 
**{int(server.filesize_limit/1024/1024)} MB**
⁍VCs bitrate limit: 
**{int(server.bitrate_limit/1000)} kbps**
''',
                     inline=True)
        em.add_field(name="\u200b", value="\u200b", inline=True)
        if server.splash:
            em.add_field(
                name="<a:banners:745844880051404834> __Invite Bg__:",
                value=f"⁍[Invite Background Image]({server.splash_url})",
                inline=True)
        if server.banner:
            em.add_field(name="<a:banners:745844880051404834> __Banner__:",
                         value=f"⁍[Server Banner]({server.banner_url})",
                         inline=True)
        em.set_thumbnail(url=server.icon_url)
        if server.banner:
            em.set_image(url=f"{server.banner_url}")
        em.set_author(
            name='Server Information',
            icon_url=
            "https://cdn.discordapp.com/emojis/296756477366894592.png?v=1")
        em.set_footer(text=f"Requested by {ctx.author}")
        await ctx.send(embed=em)
ZaddyDanger (0)

@SixBeeps I figured out the issue. It isn't about the complexity but for some reason it returns none type object for "server.owner", "server.owner.name", "server.owner.mention" and stops the execution which is weird because it works fine on my PC but on replit it returns a none type object.