'AttributeError: 'PermissionOverwrite' object has no attribute 'items' when editing a VoiceChannel
This line of code
await channel.edit(user_limit=0, name="💤|Dormant", overwrites=discord.PermissionOverwrite(read_messages = False))
Sourcing from
elif before.channel is not None and after.channel is None: # User left a channel
channel = before.channel
if len(channel.members) == 0:
print("debug 3")
if str(channel.name).startswith("Currently"):
print("debug 4")
await channel.edit(user_limit=0, name=":zzz:|Dormant", overwrites=discord.PermissionOverwrite(read_messages = False))
await asyncio.sleep(600)
await channel.edit(name="Waiting for game to be played...", roles=None, reason="The voice channel was empty")
await channel.set_permissions(role=discord.Role.name())
Returns
AttributeError: 'PermissionOverwrite' object has no attribute 'items'
Sourcing from
Ignoring exception in on_voice_state_update
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "z:\Programming\Python\Discord Bots\Channel name changer\main.py", line 37, in on_voice_state_update
await channel.edit(user_limit=0, name="💤|Dormant", overwrites=discord.PermissionOverwrite(read_messages = False))
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\channel.py", line 733, in edit
await self._edit(options, reason=reason)
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\abc.py", line 289, in _edit
for target, perm in overwrites.items():
AttributeError: 'PermissionOverwrite' object has no attribute 'items'
Why does it return that error, and what in the code needs to be addressed for it to function properly?
Solution 1:[1]
If you want the overwrite to apply to everyone, you need to use the @everyone
role for set_permissions
.
await channel.set_permissions(
ctx.guild.default_role, # applies it to @everyone of the guild
overwrite=discord.PermissionOverwrite(read_messages=False)
)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Eric Jin |