Home>

Error:

Traceback (most recent call last):
  File "D: \ Bot \ venv \ lib \ site-packages \ discord \ ext \ commands \ core.py", line 85, in wrapped
    ret= await coro (* args, ** kwargs)
  File "D: \ Bot \ bot \ cogs \ moder.py", line 148, in mute
    await member.add_roles (role)
  File "D: \ Bot \ venv \ lib \ site-packages \ discord \ member.py", line 777, in add_roles
    await req (guild_id, user_id, role.id, reason= reason)
AttributeError: 'NoneType' object has no attribute 'id'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "D: \ Bot \ venv \ lib \ site-packages \ discord \ ext \ commands \ bot.py", line 939, in invoke
    await ctx.command.invoke (ctx)
  File "D: \ Bot \ venv \ lib \ site-packages \ discord \ ext \ commands \ core.py", line 863, in invoke
    await injected (* ctx.args, ** ctx.kwargs)
  File "D: \ Bot \ venv \ lib \ site-packages \ discord \ ext \ commands \ core.py", line 94, in wrapped
    raise CommandInvokeError (exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute 'id'

My code:

def get_role (self, ctx: commands.Context):
        cur.execute (f'SELECT role_id FROM mutes WHERE guild_id= {ctx.guild.id} ')
        muteRole= cur.fetchone ()
        db.commit ()
        return muteRole
@ commands.command (name= 'set_mute_role')
    @ commands.has_permissions (manage_guild= True)
    async def set_mute_role (self, ctx, role: discord.Role, role_id: int= None):
        if role:
            cur.execute (f'UPDATE mutes SET role_id=? WHERE guild_id=? ', (role.id, ctx.guild.id))
            db.commit ()
        else:
            cur.execute (f'UPDATE mutes SET role_id=? WHERE guild_id=? ', (role_id, ctx.guild.id))
            db.commit ()
        emb= discord.Embed (title= 'Successful!', description= f '{ctx.message.author.mention}, mutation role changed to {role.mention}', color= 0x82c617)
        await ctx.send (embed= emb)
@ commands.command (name= 'mute')
    @ commands.has_permissions (ban_members= True)
    async def mute (self, ctx, member: discord.Member, *, reason= 'No reason given.'):
        role= discord.utils.get (ctx.guild.roles, id= Moder.get_role)
        await member.add_roles (role)
  • Answer # 1

    This is what the result of executing the `get_role` function looks like:` ((123456),) `

    Change the functionget_rolelike this:

    def get_role (self, ctx: commands.Context):
        cur.execute (f'SELECT role_id FROM mutes WHERE guild_id= {ctx.guild.id} ')
        muteRole= cur.fetchone () [0]
        return muteRole
    

    Everything should work. Happy coding!

  • Answer # 2

    This is what the result of executing the `get_role` function looks like:` ((123456),) `

    Change the functionget_rolelike this:

    def get_role (self, ctx: commands.Context):
        cur.execute (f'SELECT role_id FROM mutes WHERE guild_id= {ctx.guild.id} ')
        muteRole= cur.fetchone () [0]
        return muteRole
    

    Everything should work. Happy coding!