EricPlayz YT
EricPlayz YT

Reputation: 11

How can I mass lock/unlock channels in discord.py

Hello stack overflow users, I am trying to achieve mass-locking/unlocking channels in this coding language. The commands return no error, but it doesn't lock all the channels. I gave the bot permissions and coded this myself, can anyone help?

My code is here:

@my_bot.command()
@commands.has_permissions(manage_roles=True)
async def Mass_Lock(ctx):
  channels = ctx.guild.channels
  role = discord.utils.get(ctx.guild.roles, name="@everyone")
  for channel in channels:
    if channel == discord.TextChannel:
      await channel.set_permissions(role, send_messages=False)

    if channel == discord.VoiceChannel:
      await channel.set_permissions(role, speak=False, video=False, connect=False)

@my_bot.command()
@commands.has_permissions(manage_roles=True)
async def Mass_Unlock(ctx):
  channels = ctx.guild.channels
  role = discord.utils.get(ctx.guild.roles, name="@everyone")
  for channel in channels:
    if channel == discord.TextChannel:
      await channel.set_permissions(role, send_messages=True)

    if channel == discord.VoiceChannel:
      await channel.set_permissions(role, speak=True, video=True, connect=True)

Upvotes: 0

Views: 196

Answers (1)

3nws
3nws

Reputation: 1439

Your logic is wrong, to check the type of the channel you can use isinstance().

if isinstance(channel, discord.TextChannel):
    #

or alternatively:

if channel.type == discord.ChannelType.text:
    #

Also there is no video permission in VoiceChannel its called stream. so it should be like:

await channel.set_permissions(role, speak=False, stream=False, connect=False)

Upvotes: 1

Related Questions