如何使一个特定角色的锁定命令?

时间:2021-01-07 09:53:10

标签: discord.py

您可能已经看到了我刚才的问题(How do I make a lockdown command?),在那里我问如何锁定指定的通道。但是,命令只锁定了@每个人的角色。我的服务器拥有数百万的角色和其他角色做渠道的,所以我想知道如何更改ctx.guild.default_role到您指定的角色和通道锁定了该角色的东西。当前命令:

    @commands.command()
    @commands.has_permissions(manage_channels=True)
    async def lockdown(self, ctx):
        await ctx.channel.set_permissions(ctx.guild.default_role, send_messages=False)
        await ctx.send(ctx.channel.mention + " ***is now in lockdown.***")

1 个答案:

答案 0 :(得分:1)

您可以简单地将角色作为参数传递

async def lockdown(self, ctx, role: discord.Role): # `RoleConverter` will automatically convert it to a `discord.Role` instance
    await ctx.channel.set_permissions(role, send_messages=False)
    await ctx.send(ctx.channel.mention + " ***is now in lockdown.***")

您可以通过提及角色、输入角色 ID 或简单地传递角色名称来调用它