如何使用discord.py更改所有文本通道的权限?

时间:2020-02-20 11:24:40

标签: python discord.py discord.py-rewrite

我正在尝试发出一条命令来更改所有文本通道的权限 但这不起作用

@bot.command()
async def close_all(ctx):
  overwrite = discord.PermissionOverwrite()
  overwrite.send_messages = False
  overwrite.read_messages = False
  ctx.get_channel = ctx.message.server
  await ctx.channel.set_permissions(ctx.guild.default_role, overwrite=overwrite)

我也试图放guild,但它说AttributeError: 'Guild' object has no attribute 'channel'

@bot.command()
async def close_all(ctx):
  await ctx.guild.channel.set_permissions(ctx.guild.default_role, send_messages=False)

1 个答案:

答案 0 :(得分:2)

Guild没有属性channel,但确实有channels,它是行会中可以循环通过的所有频道的列表:

for chan in guild.channels:
    await chan.set_permissions(cts.guild.default_role, send_messages=False)