简体   繁体   中英

Is there a way to hide a list of channels with discord.py?

So i've been writing a bot for one of my friends servers and i can seem to get it working. I need a way to hide multiple channels. I have already written a function to give me all the channels i need to hide in an array. I need a function that when called it will iterate over the items in my array it will remove the read_messages permission from a specified user that my function also supplies.

# expected input
hide(channels_to_hide, user)

Expected output: All channels listed in channels_to_hide are hidden from user .

I have tried to use await channel.set_permissions() but cant seem to get that to work, and the docs seem a bit spacey when hiding the channels. Also im using the discord.py rewrite version.

Thanks, Soupy

You should consider a role which will hide all the given channels. You can get the role and add it like this, this is to executed inside on_raw_reaction_add

@bot.event
async def on_raw_reaction_add(payload):
    if message.author.id != bot.user.id:
        return # not to take reactions from message not made by the bot itself
    
    role = 'hide' # you can also use a list of roles 
    guild = bot.get_guild(payload.guild_id)

    user = await bot.fetch_user(payload.user_id)
    name = guild.get_member_named(user.name)
    await name.add_roles(role)

Another way to add roles is like this

role = discord.utils.get(ctx.guild.roles, name="role to add name")
user = ctx.message.author
await user.add_roles(role)

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