(Discord.py) 如何锁定和解锁语音通道

(Discord.py) How to lock and unlock voice channel

我是编程新手。在 Whosebug 和 YouTube 工作数小时后,我创建了 Bot,它允许为所有服务器用户(任何角色)自动创建临时语音频道,并在频道为空时删除这些频道。

async def on_voice_state_update(member, before, after):
    person_freq=['1', '2', '3']
    person = member.name
    
    if member.bot:
        return
    if str(after.channel) == "+ NEW":

        if str(after) != str(before):
            guild = member.guild
            freq = person_freq[0]
            act_voice_channels = (c.name for c in guild.voice_channels)
            for freq in person_freq:
                if freq not in act_voice_channels:
                    await after.channel.clone(name=freq)
                    channel = discord.utils.get(guild.voice_channels, name=freq)
                    await member.move_to(channel)
                    return
        
    if len(before.channel.members) == 0: 
        await before.channel.delete()

 

我故意删除了部分带有其他 'IF' 条件的代码。

现在我想为创建每个特定频道的成员添加本地管理员角色的权限。并在删除频道后将其删除。该本地管理员需要能够 'lock' 和 'unlock' 他自己的 voice_channel。 在“锁定”命令的情况下,除了服务器管理员之外,没有人允许加入频道。 在“解锁”命令的情况下 - 此禁令被解除。

我想我需要在这两个def中写smtn

#lock
@client.command(pass_context=True)
@commands.has_permissions(**administrator**=True)
async def lock(ctx):



#unlock
@client.command(pass_context=True)
@commands.has_permissions(**administrator**=True)
async def unlock(ctx):

考虑到可能有很多这样的渠道,我该怎么做?

感谢@ChaoticNebula 在 GitHub 上分享同样的问题。由于 discord.py 的新版本,我做了一些修正并解决了这个问题:

#lock
@client.command(pass_context=True)
@commands.has_permissions(manage_channels=True)
async def lock(ctx):
    await ctx.channel.purge (limit=1)
    channel = ctx.message.author.voice.channel
    overwrite = channel.overwrites_for(ctx.guild.default_role)
    overwrite.connect = False
    await channel.set_permissions(ctx.guild.default_role, overwrite=overwrite)


#unlock
@client.command(pass_context=True)
@commands.has_permissions(manage_channels=True)
async def unlock(ctx):
    await ctx.channel.purge (limit=1)
    channel = ctx.message.author.voice.channel
    overwrite = channel.overwrites_for(ctx.guild.default_role)
    overwrite.connect = True
    await channel.set_permissions(ctx.guild.default_role, overwrite=overwrite)