#overwrite

1 messages · Page 1 of 1 (latest)

warm ore
#
  File "C:\Users\user\Desktop\discordbot.py", line 48, in on_component
    interactions.PermissionOverwrite.for_target(guild.default_role).deny(Permissions.VIEW_CHANNEL)
TypeError: 'NoneType' object is not callable

what is the NoneType object? and why

summer veldtBOT
#

Hey! Once your issue is solved, press the button below to close this thread!

austere marsh
#

are you sure for_target and deny will always be functions

warm ore
#

wedym?

#

i usethem on a button click only

queen pier
#

What is your python version?

warm ore
#

3.12.3

queen pier
#

I'm not sure what are you trying to achieve, but PermissionOverwrite.deny (return of interactions.PermissionOverwrite.for_target(guild.default_role)) is optional Permission class (so it can be None)
So, in other words, interactions.PermissionOverwrite.for_target(guild.default_role).deny == None

warm ore
#

i wanna make a private text channel

#

that only the user who clicked a button can view, and ofc, the admins

#

channel = await ctx.guild.create_text_channel(name=f"{user.username}-certificate", permission_overwrites=overwrite)

#
    overwrite = [
        interactions.PermissionOverwrite.for_target(guild.default_role).deny(Permissions.VIEW_CHANNEL)
    ]
#

this is the overwrite array

#

what is the right aproach to do this?

austere marsh
#

you should check if the deny function is None

queen pier
#

try

overwrite = interactions.PermissionOverwrite.for_target(guild.default_role)
overwrite.add_denies(Permissions.VIEW_CHANNEL)
warm ore
#

ohh so i should use add_denies instead of deny

#
PUT::https://discord.com/api/v10/channels/1234521678420246528/permissions/636196991029739530: 403
Ignoring exception in Component(): HTTPException: 403|Forbidden || Missing Access
queen pier
#

Ping me if it works

warm ore
#

got this, and it did not create the channel

queen pier
warm ore
#

yes it does

#

its admin

#

tried changing to this

overwrite = [interactions.PermissionOverwrite.for_target(guild.default_role).add_denies(Permissions.VIEW_CHANNEL)]
#

got a whole different error

#
Traceback (most recent call last):
  File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\interactions\client\client.py", line 607, in _async_wrap
    await _coro(_event, *_args, **_kwargs)
  File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\interactions\models\internal\callback.py", line 32, in __call__
    return await self.callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user\Desktop\discordbot.py", line 52, in on_component
    channel = await ctx.guild.create_text_channel(name=f"{user.username}-certificate", permission_overwrites=overwrite)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\interactions\models\discord\guild.py", line 1005, in create_text_channel
    return await self.create_channel(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\interactions\models\discord\guild.py", line 964, in create_channel
    models.process_permission_overwrites(permission_overwrites),
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\interactions\models\discord\channel.py", line 2681, in process_permission_overwrites
    return list(map(to_dict, overwrites))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\interactions\client\utils\serializer.py", line 41, in to_dict
    attrs = fields(inst.__class__)
            ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\attr\_make.py", line 2055, in fields
    raise NotAnAttrsClassError(msg)
attr.exceptions.NotAnAttrsClassError: <class 'NoneType'> is not an attrs-decorated class.
queen pier
#

Because add_denies returns None, you need to pass overwrite object

queen pier
warm ore
warm ore
#

wait, lemme try without overwrites

#

it should create a channel

#

it works, it creates a channel without overwrites, but the channel would be public

#

ok wait worked, but now only the server owner can see the channel, even the user who made it cant see it

#

tried this

    overwrite = [interactions.PermissionOverwrite.for_target(guild.default_role), interactions.PermissionOverwrite.for_target(user)]
    overwrite[0].add_denies(Permissions.VIEW_CHANNEL)
    overwrite[1].add_allows(Permissions.VIEW_CHANNEL)
#

but still

queen pier
#

but now only the server owner can see the channel
Any user with admin permissions can see any channel (even hidden)
Owner is basically a role with admin++ powers

#

For everything else, you just need to play with permissions

warm ore
#

i gave the ctx.user permission to view channel, but it didnt apply

#

and i made sure ctx.user isnt a none, its the actual user

#

when i click the button to create a channel, it shows for a second then disappears again

warm ore
#

i tried ti workaround by adding the channel to a categiry onyl accesible by mod+, thena dd the user to the channel

#
await channel.add_permission(target=user, allow=[Permissions.VIEW_CHANNEL, Permissions.SEND_MESSAGES])