Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
909 views
in Technique[技术] by (71.8m points)

discord.py - How do I make a lockdown command for a specified role?

You may have seen my previous question (How do I make a lockdown command?), where I asked about how to lockdown specified channel. But that command only locked down the @ everyone role. My server has millions of roles and channels made for other roles, so I want to know how to change ctx.guild.default_role to something where you specify the role and the channel locks down for that role. Current command:

    @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.***")

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can simply pass the role as an argument

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.***")

You can invoke it by mentioning the role, by putting the role ID or simply by passing the name of the role


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...