这是我的代码。它将所有其他权限设置为默认,并将更改将发送消息设置为false。
@client.command()
@commands.has_permissions(manage_channels=True)
async def lock(ctx):
await ctx.channel.set_permissions(ctx.guild.default_role, send_messages=False)
await ctx.send('Channel locked.')
@lock.error
async def lock_error(ctx, error):
if isinstance(error,commands.CheckFailure):
await ctx.send('You do not have permission to use this command!')
答案 0 :(得分:0)
如果我正确理解了您的评论,则此代码应将所有其他权限保持不变,并且仅将您明确告知的权限更改为:
@client.command()
@commands.has_permissions(manage_channels=True)
async def lock(ctx):
overwrite = ctx.channel.overwrites_for(ctx.guild.default_role)
overwrite.send_messages = False
await ctx.channel.set_permissions(ctx.guild.default_role, overwrite=overwrite)
await ctx.send('Channel locked.')
@lock.error
async def lock_error(ctx, error):
if isinstance(error,commands.CheckFailure):
await ctx.send('You do not have permission to use this command!')
参考: