[英]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.
我已经写了一个 function 给我所有需要隐藏在数组中的通道。 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.我需要一个 function ,当调用它时,它将遍历我的数组中的项目,它将删除我的 function 也提供的指定用户的
read_messages
权限。
# expected input
hide(channels_to_hide, user)
Expected output: All channels listed in channels_to_hide
are hidden from user
.预期的 output:channels_to_hide 中列出的所有
channels_to_hide
都对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.我曾尝试使用
await channel.set_permissions()
但似乎无法使其正常工作,并且在隐藏频道时文档似乎有点空洞。 Also im using the discord.py rewrite version.我也在使用 discord.py 重写版本。
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
您可以像这样获取角色并添加它,这是在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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.