有没有办法用 discord.py 隐藏频道列表?
Is there a way to hide a list of channels with discord.py?
所以我一直在为我的一个朋友服务器编写一个机器人,我似乎可以让它工作。我需要一种隐藏多个频道的方法。我已经编写了一个函数来为我提供我需要隐藏在数组中的所有频道。我需要一个函数,当调用它时它将遍历我的数组中的项目,它将删除我的函数也提供的指定用户的 read_messages
权限。
# expected input
hide(channels_to_hide, user)
预期输出:channels_to_hide
中列出的所有频道对 user
隐藏。
我曾尝试使用 await channel.set_permissions()
,但似乎无法使其正常工作,并且文档在隐藏频道时看起来有点空洞。
我也在使用 discord.py 重写版本。
谢谢,
汤汁
您应该考虑一个隐藏所有给定频道的角色。
你可以获取角色并像这样添加它,这是在 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)
另一种添加角色的方法是这样的
role = discord.utils.get(ctx.guild.roles, name="role to add name")
user = ctx.message.author
await user.add_roles(role)
所以我一直在为我的一个朋友服务器编写一个机器人,我似乎可以让它工作。我需要一种隐藏多个频道的方法。我已经编写了一个函数来为我提供我需要隐藏在数组中的所有频道。我需要一个函数,当调用它时它将遍历我的数组中的项目,它将删除我的函数也提供的指定用户的 read_messages
权限。
# expected input
hide(channels_to_hide, user)
预期输出:channels_to_hide
中列出的所有频道对 user
隐藏。
我曾尝试使用 await channel.set_permissions()
,但似乎无法使其正常工作,并且文档在隐藏频道时看起来有点空洞。
我也在使用 discord.py 重写版本。
谢谢, 汤汁
您应该考虑一个隐藏所有给定频道的角色。 你可以获取角色并像这样添加它,这是在 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)
另一种添加角色的方法是这样的
role = discord.utils.get(ctx.guild.roles, name="role to add name")
user = ctx.message.author
await user.add_roles(role)