0

so i was trying to make a raidmode command and i want it to revoke send_messages perms to all channels.... but i m getting an error. any help is appriciated! :D

@commands.command(pass_context=True)
    @commands.has_permissions(administrator=True)
    async def raidmode(self, ctx, section):
        if section == 'on':

            guild = ctx.guild
            channels = guild.get_all_channels()
            role = discord.utils.get(guild.roles, name="@everyone")

            await channels.set_permissions(role, send_messages=False)
            mbed = discord.Embed(description="Raid Mode Is Enabled!", color=0xe74c3c)
            await ctx.send(embed=mbed)
            return

        if section == 'off':
            guild = ctx.guild
            channels = guild.get_all_channels()
            role = discord.utils.get(guild.roles, name="@everyone")
            await channels.set_permissions(role, send_messages=True)
            m1bed = discord.Embed(description="Raid Mode Is Disabled!", color=0xe74c3c)
            await ctx.send(embed=m1bed)
            return

ERROR

channels = guild.get_all_channels()
AttributeError: 'Guild' object has no attribute 'get_all_channels'
Nucleo __
  • 108
  • 1
  • 10
  • Keep mind that getting all channels and changing all their permissions is not scalable. If this happens a lot, you will get ratelimited. – Sachin Raja Dec 13 '20 at 14:16
  • Does this answer your question? [How to get all text channels using discord.py?](https://stackoverflow.com/questions/49446882/how-to-get-all-text-channels-using-discord-py) – GospelBG Dec 13 '20 at 14:57

1 Answers1

0

You're going to need Guild.channels

channels = ctx.guild.channels
everyone_role = guild.roles[0] # strictly get the @everyone role (lowest in hierarchy), in case an owner has a role named @everyone
for channel in channels:
    if isinstance(channel, discord.TextChannel): # don't change permissions for voice chat or categories
        await channel.set_permissions(role, send_messages=False)

Also, keep in mind that because allow permissions override deny permissions, this may not work for all channels.

Eric Jin
  • 3,836
  • 4
  • 19
  • 45