簡體   English   中英

有沒有辦法用 discord.py 隱藏頻道列表?

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

所以我一直在為我的一個朋友服務器編寫一個機器人,我似乎可以讓它工作。 我需要一種隱藏多個頻道的方法。 我已經寫了一個 function 給我所有需要隱藏在數組中的通道。 我需要一個 function ,當調用它時,它將遍歷我的數組中的項目,它將刪除我的 function 也提供的指定用戶的read_messages權限。

# expected input
hide(channels_to_hide, user)

預期的 output:channels_to_hide 中列出的所有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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM