【发布时间】:2023-03-21 10:01:02
【问题描述】:
我想将服务器所有频道的权限从 Read messages = True 更改为 False。基本上我不希望具有默认角色的用户能够看到任何频道。 我写的:
@bot.command()
async def maintainance(ctx):
channel = ctx.guild.channels
perms = channel.overwrites_for(ctx.guild.default_role)
perms.read_messages=False
for channel in ctx.guild.channels:
await channel.set_permissions(ctx.guild.default_role, overwrite=perms)
await ctx.message.add_reaction(emoji="<a:tick:748476262640779276>")
我得到的错误:
Ignoring exception in command maintainance:
Traceback (most recent call last):
File "C:\Users\Rohit\AppData\Roaming\Python\Python37\site-packages\discord\ext\commands\core.py", line 83, in wrapped
ret = await coro(*args, **kwargs)
File "c:\Users\Rohit\Desktop\discord bots\tutorial bot\bot.py", line 23, in maintainance
perms = channel.overwrites_for(ctx.guild.default_role)
AttributeError: 'list' object has no attribute 'overwrites_for'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\Rohit\AppData\Roaming\Python\Python37\site-packages\discord\ext\commands\bot.py", line 892, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\Rohit\AppData\Roaming\Python\Python37\site-packages\discord\ext\commands\core.py", line 797, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\Rohit\AppData\Roaming\Python\Python37\site-packages\discord\ext\commands\core.py", line 92, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'list' object has no attribute 'overwrites_for'
我不知道我做错了什么。
【问题讨论】:
标签: python discord discord.py