Fred the Cat
Fred the Cat

Reputation: 45

how to change permissions for all text channels with discord.py?

I'm trying to make a command to change the permissions on all text channels but it does not work

@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)

i also tried to put guild but it say 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)

Upvotes: 2

Views: 1525

Answers (1)

Connor
Connor

Reputation: 143

Guild has no attribute channel, but it does have channels which is a list of all channels in the guild that you can loop through:

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

Upvotes: 2

Related Questions