为什么我的锁定通道命令不起作用???不和谐

时间:2020-10-22 16:57:38

标签: python discord.py

我创建了一个锁定通道命令,但是当我对其进行测试时,它没有出现错误,也没有锁定通道。我搜索了互联网,但找不到任何有效的锁定命令。这是我的代码。

@client.command(pass_context=True)
@commands.has_permissions(manage_channels=True)
async def lock(ctx, channel : discord.TextChannel=None):
    channel = channel or ctx.channel
    overwrite = channel.overwrites_for(ctx.guild.default_role)
    overwrite.send_messages = False
    await channel.set_permissions(ctx.guild.default_role, overwrite=overwrite)
    await ctx.send('Channel locked.')

1 个答案:

答案 0 :(得分:0)

您错误地使用了set_permissions,请输入权限名称及其值。

如果您想要多个目标,则应使用覆盖,这里只有1个,因此我们可以直接使用权限名称。

下面是修改后的代码:

@client.command(pass_context=True)
@commands.has_permissions(manage_channels=True)
async def lock(ctx, channel : discord.TextChannel=None):
    channel = channel or ctx.channel
    await channel.set_permissions(ctx.guild.default_role, send_messages=False)
    await ctx.send('Channel locked.')