discord.py中PermissionOverwrite的一个好例子

2024-06-12 16:36:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在尝试使用这个功能,但没有掌握它的窍门。这是我试过的东西

# lockdown
@client.command()
@commands.has_permissions(administrator=True)
async def lockdown(ctx, channel: discord.TextChannel=None):
    
    channel = channel or ctx.channel
    await ctx.send("This channel has been locked. You will need to change the settings to revert this action.")

    if ctx.guild.default_role not in channel.overwrites:
        overwrites = {
        ctx.guild.default_role: discord.PermmisionOverwrite(send_messages=False)
        }
        await channel.edit(overwrites=overwrites)

但它似乎不起作用,我知道为什么。我不知道如何正确使用这个函数。看到API文档,我甚至感到困惑。我能举个好例子吗


Tags: to功能clientsenddefaultchannelawaitrole