简体   繁体   中英

Lock Channels For Everyone discord.py

so i was trying to make a raidmode command and i want it to revoke send_messages perms to all channels.... but im 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'

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM